ID3DXSprite

Started by
1 comment, last by cannonicus 18 years, 9 months ago
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
Emil Jonssonvild
Advertisement
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 direct3ddevice9LPDIRECT3D9 d3d = NULL;LPDIRECT3DDEVICE9 d3ddev = NULL;



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 spriteLPD3DXSPRITE 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    LPDIRECT3DTEXTURE9 MickyTexture = NULL;    //the struct for reading bitmap file info    D3DXIMAGE_INFO 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	D3DXCreateTextureFromFileEx(         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
d3dd3v->BeginScene();sprite_handler->Begin(d3dxsprite_alphablend); //THIS ALLOWS ALPHABLENDING OF DIFFERENT SPRITES//YOU MUST CAll Begin in order to use the draw interfaceD3DXVECTOR2 translate(50,300);D3DXVECTOR2 scaleVector(.5, 2);D3DXMATRIX mscale;D3DXMatrixTransformation2D(&mscale, NULL, NULL, &scaleVector, NULL, NULL, &translate);sprite_handler->SetTransform(&premscale);					sprite_handler->Draw(		&MickyTexture,		NULL,		NULL,		NULL,		D3DCOLOR_RGBA(255,255,255,255));sprite_handler->End();d3dd3v->EndScene();d3ddev->Present(NULL,NULL,NULL,NULL);



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.
These tears..leave scars...as they run down my face.
Thanks alot don!! Ill look into it.

/emil
Emil Jonssonvild

This topic is closed to new replies.

Advertisement