Create new PhysicsSprite

Feb 4, 2012 at 9:38 AM

Hi, I have one page (WinPhone Game) created with PhysicsHelper. On page have I two Ellipses, some rectangles. Ellipses are not static. On page create I one buuton. On click I want to create new Ellipse, but i dont know how can i do it.

Please can you send me some example with this commands? Thanks.

 

I have tried this code, but new Ellipse is not on page.

PhysicsSprite temp = _phCTR.PhysicsObjects["testEllipse"] as PhysicsSprite;
temp.Visible = true;
 _phCTR.PhysicsObjects.Add("NewEllipse", temp);

 

Thanks for all suggestion.

Julo

 

Feb 4, 2012 at 10:21 AM

This code help me.

 

Ellipse es = new Ellipse { Name = "es" , Width = 20, Height = 20, Fill = new SolidColorBrush(Colors.White ), Visibility = Visibility.Visible };
Canvas.SetLeft(es, 0);
Canvas.SetTop(es, 300);
LayoutRoot.Children.Add(es);
//Point point = endPoint;
//double num3 = (point.X - startPoint.X);
//double num4 = -(point.Y - startPoint.Y);

xna.Vector2 force = new xna.Vector2((float)( 250.0), (float)( 250.0));


System.Windows.Interactivity.BehaviorCollection bc1 = System.Windows.Interactivity.Interaction.GetBehaviors(es);


Spritehand.PhysicsBehaviors.PhysicsObjectBehavior b1 = new Spritehand.PhysicsBehaviors.PhysicsObjectBehavior();
b1.FrictionCoefficient = 0.1d;
b1.Mass = .8d;
b1.RestitutionCoefficient = 0.2d;
b1.BoundaryElement = es.Name;
bc1.Add(b1);
PhysicsObjectMain m1 = (PhysicsObjectMain)es.GetValue(PhysicsObjectMain.PhysicsObjectProperty);
PhysicsSprite flyBallPhysicsSprite = _phCTR.AddPhysicsBody(m1);
if (flyBallPhysicsSprite != null)
{
flyBallPhysicsSprite.BodyObject.LinearVelocity = new xna.Vector2(0f, 0f);
flyBallPhysicsSprite.BodyObject.Position = _phCTR.ScreenToWorld(new System.Windows.Point(0, 450));
flyBallPhysicsSprite.BodyObject.ApplyForce(force);
flyBallPhysicsSprite.BodyObject.ApplyTorque(3500f);

}