Just adding a simple object realtime keeps raining errors

Jan 5, 2010 at 4:26 PM

I just want to add a ellipse with mass 0.5 so it drops and floats on the water and this just realtime on a button press (Water is already added and one ball too, the only one which is working fine, the same with all stuff I create in the constructor).

However, no matter which tutorial or post i follow here, I either keep getting errors (Like Could not determine the outline of UIElement Ball. Could not find a point within its boundaries.) or it doesn't do anything at all.

I changed the LayoutRoot to Canvas, Add Ellipse and than add Physics Object to it (Doesn't matter if I add it on the Ellipse or Canvas, both don't work). All like the tutorials tell me. When following the blog post it's just a constant rain of errors.

Than I found something like AddPhysicsBody(Ball.LayoutRoot) or just AddPhysicsBody(Ball), but they don't effect anything at all, even if I set IsStatic to true it still falls down and no matter what I change here it doesn't work.

 

Could do with some help, tried almost everything here already, including giving everything a name and some other workarounds but none work!

And as far as I can see I'm not the only one having troubles so some more information on this would be extremely useful.

Something else I miss is how to add a force to a ball, like throwing it, there is a Force thing but I have no idea how to add it.

Coordinator
Jan 5, 2010 at 4:52 PM

Yeah, dynamically adding objects is a recurring difficulty for lots of people. I'm going to try to make this easier in the next release.

I would strongly recommend looking at the DemoBehaviors2 sample which calls AddPhysicsBodyForCanvasWithBehaviors to dynamically add a ragdoll on a button press.

Remember these notes:

(1) The physics helper has two ways of working: (a) the "old" way which uses UserControls. This was developed for Silverlight 2. (b) the "new" way of using Behaviors. This was developed for Silverlight 3, when Behaviors were added to the framework. You cannot mix these two methods, you need to choose either (a) or (b). We need to use AddPhysicsBodyForCanvasWithBehaviors when working with Behaviors.

(2) The reason for the "Could not determine outline" error is usually because the outline algorithm cannot do a HitTest until the element is visible on the screen. There are two ways around this, as explained in the threads below.

(3) It's recommended to name you elements that are assigned Physics Behaviors, and make sure the name is unique, even across different user controls! This is because the name is used to determine boundaries that have been determined previously and cached.

This thread might be useful as well:

http://physicshelper.codeplex.com/Thread/View.aspx?ThreadId=79608

One other note, to apply force, you can use the ApplyForceBehavior. There is a video here showing that - http://msbluelight-0.agappdom.net/e1/d/20709/586316/63398419200/0.sa1t_Bzv7tcVk1LvmeVojLDNu8g/zziframehtml1zz.html#%2fStartWithParent%2fappId%2f%2f%2f%2f%2f%2f%2f%2ftrue%2f1.0%2f5%2fMicrosoftAjax.js%2fBasePlayer.js%2fPlayerStrings.js%2fplayer.js%2fStartPlayer.js%2fvideo%253dhttp%253a%252f%252fmsbluelight-0.agappdom.net%252fe1%252fd%252f4147%252f21945620%252f63398419200%252f0.mYvnGMHMoJ-4EjE5j1iw0rt3Ryg%252fvideo.wmv

Jan 7, 2010 at 7:59 AM

I used AddPhysicsBodyForCanvasWithBehaviors as well but it had the same problems as the rest. When using behaviors it didn't do anything at all, where only the first added object in the constructor works. The outline errors I'm aware of but one object is already added onto the screen so that shouldn't be a problem. I already found the name thing in a thread and I named everything different but it didn't help.

That video doesn't work.

Looking forward to hear again from you.

Coordinator
Jan 7, 2010 at 11:40 AM

A couple of more things to try -

If you still have problems, can you get me a copy of your solution?