Sign in to follow this  

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

This topic is 4359 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 4359 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this