Jump to content

  • Log In with Google      Sign In   
  • Create Account


Interminable

Member Since 03 Dec 2011
Offline Last Active Private

Topics I've Started

DirectX sprite movement seems 'glitchy'

13 July 2012 - 04:36 AM

I've got a sprite that moves across the screen, slowly. I've noticed as it moves, there appear to be 'imperfections', by that I mean it looks like it changes size by about single pixel in width as it moves along, then changing back, then doing it again, etc.

I can paste code if needed, but I'm wondering if there may simply be some 'fundamental' aspect of drawing sprites in DirectX that I may have missed.

Sprite rotation woes

03 December 2011 - 10:42 AM

Hello there, I've registered in the hope of resolving some issues I've been having.

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[i].texture)
				{
					D3DXMatrixRotationZ(&walls[i].matrixRotation, 0.0);
					g_pD3DXSprite->SetTransform(&walls[i].matrixRotation);
					g_pD3DXSprite->Draw(walls[i].returnTexture(), NULL, new D3DXVECTOR3(0,0,0), &walls[i].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. :P

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. :)

PARTNERS