So I'm using Farseer to create an immovable object:
[...]
private Body body;
public Immovable(World world, ContentManager c, String s, int posx, int posy, int w, int h, String user_data)
{
texture = c.Load<Texture2D>(s);
float converted_width = ConvertUnits.ToSimUnits(w);
float converted_height = ConvertUnits.ToSimUnits(h);
float converted_posx = ConvertUnits.ToSimUnits(posx);
float converted_posy = ConvertUnits.ToSimUnits(posy);
body = BodyFactory.CreateRectangle(world, converted_width, converted_height, 1.0f, new Vector2(converted_posx, converted_posy), user_data);
body.BodyType = BodyType.Static;
width = w;
height = h;
x = posx;
y = posy;
}
What I'm trying to do is keep separate my values for screen units (here, width, height, x, and y) and my values for simulated units (here, stored in body). This way, later, when I draw the object to the screen, I can:
public virtual void Draw(SpriteBatch sb)
{
sb.Draw(texture, new Rectangle(x, y, width, height), Color.White);
}
This way, when I instantiate things, I can visualize them as screen coordinates, which should hopefully keep me sane during all this! Theoretically (especially as these objects don't move), these two coordinate pairs should be in the same spot (or off by a maximum of one pixel if I'm truncating floats to an int somewhere).
However, for some reason, my rectangles are being offset by ~25 pixels up and to the left. Here's a screenshot:
You can see that he has "landed" just above where the rectangle is being drawn. I can float around the box to explore where the physics engine believes it is, and I find that it's up and left about 25 pixels.
Any ideas on what could be causing this?
new Vector2(width/2, height/2)
. The one you're using is only really useful when you want to specify a sprite size. \$\endgroup\$