Jump to content
  • Advertisement
Sign in to follow this  
binaryV

Puzzled by odd issue with 2D Coordinates

This topic is 3791 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

I'm making my first game using DirectX which happens to be a 2D game. I'm having a an odd issue with where i'm theoretically drawing sprites, and where they actually appear on screen. I drew some lines on the screen to give me a visual coordinate system. I have a 50x50 bitmap that i've loaded as a texture and using an ID3DXSprite* to draw, the screen resolution is 800x600, and I have vertical line drawn across the entire screen at x = 400 as well as a horizontal line drawn across the entire screen at y = 500. Now if I were to do this:
D3DXVECTOR3 center(25.0f, 25.0f, 0.0f);
D3DXVECTOR3 position(350.0f, 450.0f, 0.0f);
sprite->draw(&texture, NULL, &center, &position, 0xffffffff);

The sprite (which is just a box), is drawn evidently about 10 pixels away its x2 and y2 (400, 500). Therefore, i'd have to artifically shift the position vector 10 units on the xy plane to get it properly positioned on screen. My question is why the heck is this? Or am I doing something wrong? Sorry if I didn't use the code tag correctly, I dunno what the proper way is.

Share this post


Link to post
Share on other sites
Advertisement
Drawing a 50x50 bitmap centred around (25,25) at (350,450) should draw between (325, 425) and (375, 475) so I'm not sure why you expect it to get to (400,500).

However, I suspect that you have another problem, except from wrong expectations, and that's the texture being rounded to a size that's a power of 2, i.e. 64x64. A 64x64 sprite centred around (25,25) will reach (389, 489), which is about where you describe it is.

D3DXCreateTextureFromFile will round all textures to powers of 2. If you want to load a texture without such scaling, you need to use D3DXCreateTextureFromFileEx and pass D3DX_DEFAULT_NONPOW2 in the width and height parameters.

Share this post


Link to post
Share on other sites
I figured I was misunderstanding the concept of the center vector in the context of drawing the sprite. Thanks.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!