# D3DXSprite

## Recommended Posts

utilae    188
I am using C++ and Direct3D9. Using D3DXSprite, how do you set a sprites position? When you use D3DXFont with D3DXSprite, how do you specify the position of the text? I want to specify the z value, so that I can make a sprite appear in front of text or vice versa. Anyone know? Someone must. I need answers :)

##### Share on other sites
The structure of the ID3DXSprite interface states that ID3DXSprite::Draw() method will give you a parameter called CONST D3DXVECTOR3 * pPosition that is used to define where the sprite is in screen space (default) but you could change this and when you begin the rendering of the sprite you can state D3DXSPRITE_OBJECTSPACE.

The world, view, and projection transforms are not modified. The transforms currently set to the device are used to transform the sprites when the batched sprites are drawn (when Flush or End is called). If this flag is not specified, then world, view, and projection transforms are modified so that sprites are drawn in screen-space coordinates.

Also for ID3DXFont, ID3DXFont::DrawText() gives you the parameter LPRECT pRect that lets you specify a rectangle to render the text into.

But... with all that said, if you are rendering the sprite before you render the text, your text should appear ontop of your sprite.

simple example
//Render your spriteusing (Sprite sprite = new Sprite(renderer.Device)){    sprite.Begin(SpriteFlags.None);    sprite.Draw(texture, new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 0.0f), Color.White.ToArgb());    sprite.End();}//Render your textdebug.Display("Frames per second: " + timer.FPS.ToString(), 16, Color.Yellow);

I hope this helps.
Take care.

##### Share on other sites
utilae    188
Ok, thanks.

I know what I am going to do now.

## Create an account

Register a new account