Sign in to follow this  
binaryV

Puzzled by odd issue with 2D Coordinates

Recommended Posts

binaryV    122
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
ET3D    810
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

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