Advertisement Jump to content
Sign in to follow this  


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

Hi everybody Ive desided to look into the ID3DXSprite interface since it appears to be a powerful tool. Are there any nice tutorials/samples explaining the basic consepts and usage of the interface? I searched google "ID3DXSprite Samples" but i found nothing. //Emil

Share this post

Link to post
Share on other sites
well you could go to msdn they have a pretty comprehensive explanation but I will give you an overview.

The first thing you need to do is set up direct3d(I will assume that you already know how to do this so I will just overview it)

//so you have the handle for the direct3ddevice9

then you need to do is create a pointer for your sprite. This will be the way you access and controll the ID3DXSPRITE.

//this declares a pointer for the sprite
LPD3DXSPRITE sprite_handler;

despite what it seems, you dont need a sprite object for every sprite you want to draw in the gameworld. That is why I named it sprite_handler instead of something spacific like Micky_sprite.

Before you can use the pointer you have to create the sprite inteface and with sprite_handler pointing to the interface

//now the sprite_handler points to a sprite.
D3DXCreateSprite(d3ddev, &sprite_handler);

to draw the sprite you need to first load a texture into memory.
you can do this with the following:

//the texture pointer

//the struct for reading bitmap file info

//standard Windows return value
HRESULT result;

//get width and height from bitmap file
result = D3DXGetImageInfoFromFile(filename, &info);
if (result != D3D_OK)
return NULL;

//create the new texture by loading a bitmap image file
d3ddev, //Direct3D device object
"Micky.bmp", //bitmap filename
info.Width, //bitmap image width
info.Height, //bitmap image height
1, //mip-map levels (1 for no chain)
D3DPOOL_DEFAULT, //the type of surface (standard)
D3DFMT_UNKNOWN, //surface format (default)
D3DPOOL_DEFAULT, //memory class for the texture
D3DX_DEFAULT, //image filter
D3DX_DEFAULT, //mip filter
D3DCOLOR_XRGB(255,0,255), //color key for transparency (anytime d3d finds this color it will turn it transparent.
&info, //bitmap file info (from loaded file)
NULL, //color palette
&MickyTexture ); //destination texture

//make sure the bitmap textre was loaded correctly
if (result != D3D_OK)
MessageBox(hwnd, "unable to create texture", "error", MB_OK);

now that you have a texture you can draw it on the screen as a sprite using the sprite interface

sprite_handler->Begin(d3dxsprite_alphablend); //THIS ALLOWS ALPHABLENDING OF DIFFERENT SPRITES
//YOU MUST CAll Begin in order to use the draw interface

D3DXVECTOR2 translate(50,300);
D3DXVECTOR2 scaleVector(.5, 2);
D3DXMATRIX mscale;
D3DXMatrixTransformation2D(&mscale, NULL, NULL, &scaleVector, NULL, NULL, &translate);



there you go. I am sure I missed a few things But i gave you the names of may inportant functions so just go to msdn and look them up. IT has much more information that I do.

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!