/// <summary> /// Adds a single Physics Sprite into the Physics simulation. /// </summary> /// <param name="cnvContainer">The container to add items from.</param> 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; //PhysicsUtilities.DebugVisualTree(this, 1); this.Children.Add(element); PhysicsObjects.Add(thisName, element); element.Update(); element.Collision += new PhysicsSprite.CollisionHandler(polygon_Collision); } if (MousePickEnabled) { element.MousePickEnabled = true; } return element; }