ID3DXSprite::Draw - figuring out what center and position do

Started by
0 comments, last by devronious 18 years, 3 months ago
Alright, I'm making a little 2D sidescroller and I can get Megaman to run around jump using the arrow keys. Cool. So now I'm trying to add blocks to collide with and I ran into a problem - how _exactly_ do those center and position vectors behave? I'm using the Extended Sprite Template talked about in the of the articles here and that seems to work. Now, what do I want to use for my center vector? What about my position displacement? I'm just a little fuzzy on the best way to logically organize my sprites and then be later able to determine if a bounding polygon collides with a nother bounding polygon.
Advertisement
Center is the center of the texture in pixels, ie: for a 256x256 texture the center would be 128,128 (this would be center justified drawing). It's like justifying text. If I wanted upperleft justified sprite then I would set the center to 0,0. If I wanted lowerright justified then I would set the center to 256,256, lowereft would be 0,256 and so on.

position is the position to display the sprite in screen coordinates. ie: if my form window was 640,480 then a position of 320,240 would be in the center of the screen. So far I've only used x and y. Now if you set the flag for Sprite.Begin() to ObjectSpace then the position would be a position if world coordinates instead of screen coordinates and would be defined by x,y,z.

It's best I think to set the center to the center of the texture and the position to 0,0,0. In this way you would set the position by passing a matrix to the Sprite.Transform member. So if you wanted a sprite to appear at 100,100,50 you would pass Matrix.Translation(new Vector3(100,100,50)) to the Sprite.Transform member.

One thing that is important to note is that if your only drawing a portion of the texture by passing a rectangle in the Sprite.Draw method then the center of the Sprite should be set to (half the rectangle width), (half the rectangle height). This justifies the sprite to the center of the rectangle region properly. For upperleft justified you would set the center to 0,0 and lower right would be (rectangle height), (rectangle width) and so on.

HTH,

Devin

This topic is closed to new replies.

Advertisement