1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
class Sprite
{
private:
LPDIRECT3DDEVICE9 sprDevice=NULL;
LPD3DXSPRITE sprSprite=NULL;
LPDIRECT3DTEXTURE9 sprTexture=NULL;
public:
int x=0;
int y=0;
int width=0;
int height=0;
bool visible=false;
Sprite(LPDIRECT3DDEVICE9 DXDev, string strFileImage)
{
sprDevice=DXDev;
D3DXIMAGE_INFO d3dIInfo;
D3DXCreateSprite(sprDevice,&sprSprite);
D3DXGetImageInfoFromFile(strFileImage.c_str(), &d3dIInfo);
D3DXCreateTextureFromFile(sprDevice,strFileImage.c_str(),&sprTexture);
width=d3dIInfo.Width;
height=d3dIInfo.Height;
visible=true;
}
Sprite(LPDIRECT3DDEVICE9 DXDev, UINT ResourCeID)
{
sprDevice=DXDev;
D3DXIMAGE_INFO d3dIInfo;
D3DXCreateSprite(sprDevice,&sprSprite);
D3DXGetImageInfoFromResource(GetModuleHandle(NULL),MAKEINTRESOURCE(ResourCeID),&d3dIInfo);
D3DXCreateTextureFromResource(sprDevice,GetModuleHandle(NULL),MAKEINTRESOURCE(ResourCeID),&sprTexture);
width=d3dIInfo.Width;
height=d3dIInfo.Height;
visible=true;
}
void Image(LPDIRECT3DDEVICE9 DXDev, string strFileImage)
{
D3DXIMAGE_INFO d3dIInfo;
sprDevice=DXDev;
D3DXGetImageInfoFromFile(strFileImage.c_str(), &d3dIInfo);
D3DXCreateTextureFromFile(sprDevice,strFileImage.c_str(),&sprTexture);
width=d3dIInfo.Width;
height=d3dIInfo.Height;
visible=true;
}
void Image(LPDIRECT3DDEVICE9 DXDev, UINT ResourCeID)
{
D3DXIMAGE_INFO d3dIInfo;
sprDevice=DXDev;
D3DXGetImageInfoFromResource(GetModuleHandle(NULL),MAKEINTRESOURCE(ResourCeID),&d3dIInfo);
D3DXCreateTextureFromResource(sprDevice,GetModuleHandle(NULL),MAKEINTRESOURCE(ResourCeID),&sprTexture);
width=d3dIInfo.Width;
height=d3dIInfo.Height;
visible=true;
}
void Draw(D3DCOLOR dxColor=D3DCOLOR_XRGB(255,255,255))
{
D3DXVECTOR3 vcPosition;
vcPosition.x=x;
vcPosition.y=y;
vcPosition.z=0;
sprSprite->Begin(D3DXSPRITE_ALPHABLEND);
sprSprite->Draw(sprTexture,NULL,NULL,&vcPosition,dxColor);
sprSprite->End();
}
~Sprite()
{
if( sprSprite != NULL )
sprSprite->Release();
if( sprTexture != NULL )
sprTexture->Release();
}
};
|