Changing the "isstatic" Property on an object

Aug 23, 2011 at 6:14 AM

I've been trying to figure out how to change the isstatic property of an object (such as a ball) in code. I want to have it where the objects start out static, but then can later on fall according to physics.

Based on the physics helper home page i thought it would just be

_physicsController.PhysicsObjects["ball"].GeometryObject.IsStatic = false;



For whatever reason i get an error saying that Spritehand.FarseerHelper.PhysicsSprite does not contain a definition for GeometryObject

So from there I tried:

_physicsController.PhysicsObjects["ball"].BodyObject.IsStatic = false;

Here i get a runtime error where the program basically crashes upon launch.


Any help would be much appreciated!

Thanks, Kyle


Aug 23, 2011 at 4:08 PM

Yes, the GeometryObject is outdated - since the newer version of the Farseer engine some things changed. I updated those docs on the home page to reflect the difference.

So for your current crash, I am guessing that the sprite "ball" does not exist.

Place a breakpoint on that line where you access PhysicsObjects, then go to the Watch Window and check the _physicsController.PhysicsObjects dictionary (you can look at the keys like so):


... just change the (0) to 1,2,3, etc. Or better yet add a debug method that writes them out to the debug window.

This will show you all of your sprite key values that are valid to access.

Aug 24, 2011 at 6:05 AM

I am getting the physics controller like you show above, however the physicsobjects property is returning null. It looks like there may not be some initialization done or something. How do i check to see if the objects get added to the controller, i feel like im missing something here.


Aug 24, 2011 at 12:59 PM

Try to handle the Initialized event on the PhysicsController and access your objects in that event. The Initialized event fires after the physics objects have been created.

Aug 25, 2011 at 5:15 AM

Thanks for the help! I managed to get this working, I eventually stumbled upon an example under the source code tab where I found out that you need to initialize the PhysicsController in  MainPage_Loaded as opposed to MainPage. This seemed to solve the problem.

Jun 19, 2012 at 4:15 PM

I was having the same problem and this was the answer. Thank you so much!!!