Change the color of a Fixture

Topics: Developer Forum, User Forum
Feb 25, 2011 at 11:55 AM
Edited Feb 25, 2011 at 11:56 AM

Hello everyone,

I have recently started using farseer and for now I am building my game using the samples provided. I have been trying to find how to change the color of a fixture for some time now and I can't seem to do it. Searching the forums only gave me discussions about transition from farseer 2.0 to 3.0, which is unrelated to my problem.

For example, in Demo7Screen.cs from the samples provided here (Farseer Physics Engine 3.2 SimpleSamples Silverlight) there is this very simple code :

 

Fixture[] rect = new Fixture[4];

for (int i = 0; i < 4; i++)
{
	rect[i] = FixtureFactory.CreateRectangle(World, 6, 1.5f, 1);
}

 

Now let's say I want a rectangle to be red. I can't find a single thing related to color in the properties of the Fixture.
How can I achieve this ?
Thanks,
carve
Developer
Feb 25, 2011 at 2:13 PM

Farseer is a physics engine and has nothing to do with drawing and how you represent your objects on the screen. Hence you will never find any information like color, texture, etc. in any Farseer object. If you need such information attached to bodies/fixtures you have to do that for yourself by creating an object holding this information and adding it to the UserData field of the Fixture/Body.

Then in your drawing code you can cast the UserData to your custom class, look up the color and use that for rendering.

Feb 25, 2011 at 2:37 PM

Thanks a lot, I managed to do what I wanted using the UserData field and a test in the draw function.