I've been working on teach myself how to code with DirectX etc.
To the point, I've been trying to make a 2D game. The time has come where I need to rotate sprites. It appears the way to do this is using D3DXMatrix, ID3DXSprite's SetTransform, with either D3DXMatrixRotationZ or D3DXMatrixTransformation2D.
I have tried both D3DXMatrixRotationZ and D3DXMatrixTransformation2D and have run in to problems with each.
With D3DXMatrixRotationZ, everything appears to rotate. All my walls, along with the player. In addition, it appears to rotate the axis as well; if I say, rotated my player 90 degrees clockwise and hit left, he would move down.
With D3DXMatrixTransformation2D, the above happens, but it also moves all the walls when I move the player as well, which is even worse.
As it was evident that SetTransform applied changes to EVERY sprite I had, I decided that it might be possible to set it to something else for each time I draw a sprite (I believe I 'could' use multiple ID3DXSprite objects, but I from what I've read I gather that would be highly inefficient and the wrong way to go about dealing with this).
So:
g_pD3DXSprite->Begin(D3DXSPRITE_ALPHABLEND);
D3DXMatrixRotationZ(&player01.matrixRotation, player01.rotation);
g_pD3DXSprite->SetTransform(&player01.matrixRotation);
g_pD3DXSprite->Draw(player01.returnTexture(), NULL, new D3DXVECTOR3(0,0,0), &player01.coordinates, 0xffffffff);
if(!walls.empty())
{
for(unsigned int i=0;i<=walls.size()-1;i++)
{
if(g_pD3DXSprite && walls.texture)
{
D3DXMatrixRotationZ(&walls.matrixRotation, 0.0);
g_pD3DXSprite->SetTransform(&walls.matrixRotation);
g_pD3DXSprite->Draw(walls.returnTexture(), NULL, new D3DXVECTOR3(0,0,0), &walls.coordinates, 0xffffffff);
}
}
}
g_pD3DXSprite->End();
Initially it looked promising, it drew the walls orientated in the right direction, and it appeared to draw the player rotated as I wanted it. However, it WAS rotating the wall, just not visibly. At this point I was tearing my hair out as it took me ages to get to that position.
So basically, the problems:
- Rotating just one sprite, not every sprite.
- Rotating a sprite visibly, but not its axis.
I would greatly appreciate any help and input. I can provide further code that I have if needed.
Thanks in advance.