Nov 9, 2012 at 7:55 PM

Not sure I understand the point of having the InternalName assigned to BodyObject.UserData and the relevant fixtures . Why have it available in the PhysicsSprite CollisionHandler?

Nov 9, 2012 at 8:14 PM

PhysicsSprite.HandleOnCollision uses the fixture.UserData property to translate from the Farseer Fixture object to a sprite in the Physics Helper's Dictionary of sprites. Not sure how else to bridge that gap except to iterate through all sprite's fixtures to find a match?

Maybe I don't understand the question though.

Nov 9, 2012 at 11:31 PM
Edited Nov 9, 2012 at 11:36 PM

Here's my quandry. I'm raycasting the world object in order to find an element to delete. For example:

physicsCanvas.Simulator.RayCast((f, p, n, fr) =>
                            if (f.Body.UserData.GetType() == typeof(String))
                                PhysicsSprite sprite1;
                                physicsCanvas.PhysicsObjects.TryGetValue((String)f.Body.UserData, out sprite1);

                                if (sprite1.UserData != null)
                                    if ((FruitHelper.FruitType)sprite1.UserData == (FruitHelper.FruitType)physicsSprite.UserData)
                                        if (!uncheckedNeighbors.Contains((String)f.Body.UserData) && !cullList.Contains(sprite1))
                            return 0;
                        }, PhysicsCanvas.BoundaryHelper.ScreenToWorld(testSprite.Position), PhysicsCanvas.BoundaryHelper.ScreenToWorld(testSprite.Position + testPoint));

How can I find the unique object in the PhysicsObjects dictionary in order to remove said element from the physicsCanvas?

Nov 9, 2012 at 11:52 PM
Edited Nov 9, 2012 at 11:56 PM

I'm adding several UserControls and all have the same x:Name. I think I'll have to customize the code for my project.

BTW Thanks for writing PhysicsHelperXaml!

Nov 10, 2012 at 12:15 AM

Found my problem.


public PhysicsSprite AddPhysicsSprite(PhysicsSprite element, bool enablePhysics)
            if (enablePhysics)
                string thisName = element.GetValue(Canvas.NameProperty).ToString();
                element.SetValue(Canvas.TagProperty, thisName); // save original name in tag

                if ((element.Parent as Panel).Children.IndexOf(element) < 0)
                    throw new Exception("Could not find element " + thisName + " in the parent");
                (element.Parent as Panel).Children.Remove(element);

                thisName = PhysicsUtilities.EnsureUniqueName(this, element, thisName);  // get a unique name in the game canvas
                element.Name = thisName;
                element.InternalName = thisName; <----- ADDED THIS

                //PhysicsUtilities.DebugVisualTree(this, 1);


                PhysicsObjects.Add(thisName, element);

                element.Collision += new PhysicsSprite.CollisionHandler(polygon_Collision);

            if (MousePickEnabled)
                element.MousePickEnabled = true;

            return element;