How to rotate a sprite using D3DXSprite
ID3DXSprite::SetTransform() allows you to specify a matrix to use as the sprite's world transform matrix.
To generate this matrix, use the D3DX function D3DXMatrixTransformation().
To generate this matrix, use the D3DX function D3DXMatrixTransformation().
If I am using the same sprite handler
//sprite handler
LPD3DXSPRITE sprite_handler;
will D3DXMatrixTransformation2D() take affect on both of them or just one?
//sprite handler
LPD3DXSPRITE sprite_handler;
will D3DXMatrixTransformation2D() take affect on both of them or just one?
ID3DXSprite::SetTransform() will use the specified matrix for every ID3DXSprite::Draw() until SetTransform called again.
Quote:Original post by Sc4Freak
ID3DXSprite::SetTransform() will use the specified matrix for every ID3DXSprite::Draw() until SetTransform called again.
I tryed it.
if (d3ddev->BeginScene()) { //erase the entire background d3ddev->StretchRect(back, NULL, backbuffer, NULL, D3DTEXF_NONE); //start sprite handler sprite_handler->Begin(D3DXSPRITE_ALPHABLEND); //draw the ball position.x = 40;//(float)ball.x; position.y = 100;//(float)ball.y; sprite_handler->Draw( ball_image, NULL, NULL, &position, D3DCOLOR_XRGB(255,255,255)); // Texture being used is 64 by 64: D3DXVECTOR2 spriteCentre=D3DXVECTOR2(45.0f,13.5f); // Screen position of the sprite D3DXVECTOR2 trans=D3DXVECTOR2(550.0f,200.0f); // Rotate based on the time passed float rotation=4.7; // Build our matrix to rotate, scale and position our sprite D3DXMATRIX mat; D3DXVECTOR2 scaling(1.0f,1.0f);// out, scaling centre, scaling rotation, scaling, rotation centre, rotation, translationD3DXMatrixTransformation2D(&mat,NULL,0.0,&scaling,&spriteCentre,rotation,&trans); // Tell the sprite about the matrix sprite_handler->SetTransform(&mat); sprite_handler->Draw( paddle_image, NULL, NULL, NULL, D3DCOLOR_XRGB(255,255,255)); //stop drawing sprite_handler->End(); //stop rendering d3ddev->EndScene(); } //display the back buffer on the screen d3ddev->Present(NULL, NULL, NULL, NULL);
so when I use SetTransform it changes all the sprites not just one that I want it to change.
How can I fix that?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement