This project has moved and is read-only. For the latest updates, please go here.

Background geometry

Oct 18, 2008 at 6:57 PM
I am trying to create a simple side scrolling game. Currently I am just trying to get the collision with the world working. I have a back ground image that is 800x600, the same as the window with its origin being set at 400,300 and it is drawn at 400,300 so that it fills the screen. There is a line on this that I want the player to walk on but the collision is way out, it follows a rough idea of where the line is but about 300 pixels above it.

I am declaring the body using the vertices list of the line the player walks on and then to the bottom of the image so it creates a filled image. Firstly does it matter which way around the shape they are declared in, I.E clockwise or anticlockwise. And would the geometry vertices be the same as the that of the body, or are the relative to the body in some way? Should the body be the whole 800x600 image?

I have looked for any kind of documentation but can't find any.

Thanks for any help you give me.
Oct 18, 2008 at 7:34 PM
Download the latest source code. While the documentation is still not completely finished it is much more complete and should give you a much better idea of what you need.
Oct 18, 2008 at 7:37 PM
Does 2.0 work with XNA 2? Or will I have to get 3?
Oct 18, 2008 at 7:40 PM
Hi Android08. Welcome to Farseer Physics.

All geometries should have 0,0 as the center. This means that all your vertices should be relative to 0,0 in the vertices list.
Bodies are positioned by the center and not the upper left corner. So when you position an object like this:

body.Position = new Vector2(100,100);

The body's center would be at 100,100.
The vertices you define, should be in a counter clockwise order. If you define them in a clock wise order, Farseer will correcy them for you.

About the documentation, we are working on getting some good documentation out the door with the release of Farseer Physics 2.0.
Oct 18, 2008 at 7:42 PM
Farseer Physics 2.0 will be released with support for XNA 3.0. Getting it to work in XNA 2.0 is just a matter of coping all files into a XNA 2.0 project. Nothing else should be required.

XNA3.0 beta is the current XNA release, 3.0 will be released 30. october.
Oct 18, 2008 at 9:16 PM
Ok, Thanks for the help. I think it was because I was using the geometry factory it wasn't behaving how I expected it to. I stopped using it and used new Geom(...) and got it working. Part of the problem was the offset from the centre of the body.

Thanks again.
Oct 18, 2008 at 10:38 PM
Yes. This is also noted in the new documentation.

Farseer prefer that the vertices are centered around the centroid of the polygon. If you use the GeomFactory, this is done automatically for you. This is what you do:

Vertices vertices = new Vertices();
.. Add all your vectors

Vector2 origin = vertices.GetCentroid(); 

And in your draw method:
SpriteBatch.Draw(_texture, _body.Position, null, Color.White,
                                           _body.Rotation, origin, 1, SpriteEffects.None, 0);