Is there a demo which can introduce how to add physics behaviors Programmatically?

Dec 8, 2009 at 9:22 AM

Is there a demo which can introduce how to add physics behaviors Programmatically.

After I scan this page:   http://www.andybeaulieu.com/Home/tabid/67/EntryID/168/Default.aspx

I tried to add physics behaviors Programmatically,but I met a lot of errors.

Is there a demo whick can introduce how to add physics behavios in the way you introduced in the page above.

Coordinator
Dec 8, 2009 at 10:18 AM

In the main Physics Helper download, take a look at the DemoBehaviors2 project. It adds a Rag Doll programmatically when the "Add New Doll" button is clicked.

http://www.andybeaulieu.com/silverlight/3.0/physicshelper3/DemoBehaviors2TestPage.html

Dec 8, 2009 at 10:25 AM

yeah,I have learnt the Demo,but it shows how to "Adding User Controls Programmatically".Is there a demo which shows how to "Adding Physics Behaviors Programmatically" to an exist User Control?

Coordinator
Dec 8, 2009 at 11:51 AM

No, there isn't anything in the download to show adding the Behaviors themselves programmatically, just the completed UserControl.

But it should be pretty much the same. What kind of errors are you seeing? Are they related to the BoundaryHelper? Because there is an issue with Boundary Detection where elements must be drawn on the screen before their boundary can be determined. So if you add a new UI element to your Canvas and then immediately try to AddPhysicsBodyForCanvasWithBehaviors, you'll get an error raised from the bounary detection.

There are a couple of ways around this:

1. Ensure that at least one instance of the element you want to add is on the Canvas when the Physics controls first start up. This will add the boundaries to the cache so that subsequent elements will re-use the boundary determination from the cache.

2. Have a delay between the time that you add the elements to the screen, and when you call the AddPhysicsBodyForCanvasWithBehaviors. This will allow the element to be drawn to the screen so the boundary detection can succeed. An empty StoryBoard is the quickest way to create this delay - just use the Completed event and set the StoryBoard to 20 milliseconds or so.

(In your case sounds like you need Option #2 because you are adding Behaviors at runtime)

Hope this helps

Dec 8, 2009 at 11:56 AM
Thanks a lot,I'll try #2.

2009/12/8 AndyBeaulieu <notifications@codeplex.com>

From: AndyBeaulieu

No, there isn't anything in the download to show adding the Behaviors themselves programmatically, just the completed UserControl.

But it should be pretty much the same. What kind of errors are you seeing? Are they related to the BoundaryHelper? Because there is an issue with Boundary Detection where elements must be drawn on the screen before their boundary can be determined. So if you add a new UI element to your Canvas and then immediately try to AddPhysicsBodyForCanvasWithBehaviors, you'll get an error raised from the bounary detection.

There are a couple of ways around this:

1. Ensure that at least one instance of the element you want to add is on the Canvas when the Physics controls first start up. This will add the boundaries to the cache so that subsequent elements will re-use the boundary determination from the cache.

2. Have a delay between the time that you add the elements to the screen, and when you call the AddPhysicsBodyForCanvasWithBehaviors. This will allow the element to be drawn to the screen so the boundary detection can succeed. An empty StoryBoard is the quickest way to create this delay - just use the Completed event and set the StoryBoard to 20 milliseconds or so.

(In your case sounds like you need Option #2 because you are adding Behaviors at runtime)

Hope this helps

Read the full discussion online.

To add a post to this discussion, reply to this email (PhysicsHelper@discussions.codeplex.com)

To start a new discussion for this project, email PhysicsHelper@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com