This project has moved. For the latest updates, please go here.

Sprite Positioning

Oct 30, 2007 at 6:34 PM
I'm really frustrated with how to position my sprites. I think the positioning in my sprite class is totally screwed to be honest. It seems like no matter what I do, it ends up offset from the physics body.

Right now I have an Object class that holds the Body, Mesh, and Sprite, with an Update method to update the sprite position with the position of the body. The sprite draws with its offset in the middle. (Sprites are drawn by a separate SpriteManager)

Any suggestions? I would post some of my code, but tbh I'm more interested in the correct way of doing it rather than what is broken in my code. :P
Oct 30, 2007 at 7:13 PM
can you look at the quickstart demo I included with the download and copy that?

post some code and maybe i or someone else can spot the problem.
Oct 30, 2007 at 9:20 PM
I remember having problems because I was assuming that the spritebatch was drawing sprites positioned with their upper left corners, which it does, when you use the basic spritebatch.draw() method. However, I think when you use the draw() method that allows a rotation, it's a bit different. Since you are required to specify an origin relative to the upper left corner, the spritebatch assumes that the position vector points to your specified origin.

In other words, the position given in spritebatch.draw() always refers to the position of the origin. The default origin is the upper left hand corner, but sometimes you specify a new one for rotation (maybe the center).

Hope this helps.
Oct 30, 2007 at 9:39 PM
I fixed it. I was using the sprite's size as the reference for the origin instead of its texture. :P