Translating Sprites?

Started by
1 comment, last by streamer 17 years, 5 months ago
Hello, Sorry i'm a bit new to directx. I followed a tutorial about how to draw sprites to the screen which i found useful. But i can't seem to work out how to translate a sprite using the same matrix as i use for every other translation. E.g. if i translate a box by 10 and the sprite by 10, they do not end up in the same place. Below is the code i use at the moment. D3DXVECTOR3 vCenter( 0.0f, 0.0f, 0.0f ); D3DXVECTOR3 vPosition( 10.0f, 0.0f, 0.0f ); g_pSprite->Begin( D3DXSPRITE_ALPHABLEND ); g_pSprite->Draw( g_pTexture,&srcRect,&vCenter,&vPosition, D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f) ); Any help is most appreciated :)
Advertisement
use g_pSprite->SetTransform( D3DXMatrix ). You can make multiple calls inbetween Draw()'s to draw multiple sprites.

For example:

g_pSprite->Begin( D3DXSPRITE_ALPHABLEND );g_pSprite->SetTransform( someMatrix );g_pSprite->Draw( g_pTexture,&srcRect,&vCenter,&vPosition, D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f) );g_pSprite->SetTransform( anotherMatrix );g_pSprite->Draw( g_pTexture,&srcRect,&vCenter,&vPosition, D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f) );g_pSprite->End();


For 'someMatrix' you may want to generate it using D3DXMatrixTransformation().
Or use something like this.
With this you can move, scale and rotate sprite.

This topic is closed to new replies.

Advertisement