Puzzled by odd issue with 2D Coordinates

Started by
1 comment, last by binaryV 16 years, 1 month ago
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.
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.
I figured I was misunderstanding the concept of the center vector in the context of drawing the sprite. Thanks.

This topic is closed to new replies.

Advertisement