I'm having trouble getting my sprite to go from the right side of my screen to the left and then swap images so it appears to be walking back to the right side and then repeat that process. Ive manage to only get the cats to walk to either direction at the same time, never one after the other.

It's a lot of code so I'll grab the important pieces.

Here I create the necessary instances of the sprites

LPDIRECT3DTEXTURE9 caveman_image;
LPDIRECT3DTEXTURE9 cat_image;
LPDIRECT3DTEXTURE9 cat2_image;
SPRITE cat2;
SPRITE cat;
SPRITE caveman;
LPDIRECT3DSURFACE9 back;
LPD3DXSPRITE sprite_handler;

HRESULT result;

//timing variable
long start = GetTickCount();
long start2 = GetTickCount();
long space = GetTickCount();

RECT rect1, rect2, rect3, rect4;

Here I set the sprites to a certain size and attach that to the rect variable

;
	cat.movex = 5;
	cat.movey = 0;

	cat2.x = -100;
	cat2.y = 150;
	cat2.width = 100;
	cat2.height = 96;
	cat2.curframe = 0;
	cat2.lastframe = 5;
	cat2.animdelay = 2;
	cat2.animcount = 0;
	cat2.movex = 5;
	cat2.movey = 0;

	

	rect1.left = cat.x-1;
	rect1.right = cat.x+cat.width+1;
	rect1.top = cat.y-1;
	rect1.bottom = cat.y+cat.height+1;

	rect2.left = cat2.x+1;
	rect2.right = cat2.x+cat2.width-1;
	rect2.top = cat2.y+1;
	rect2.bottom = cat2.y+cat2.height-1;

And here is where I can't seem to get the cat to do what I need it to. I left the animation portion out since that isn't important at the moment since once I reintroduce that the animations will respond.

if(GetTickCount() - start2 >= 30)
	{
		start2 = GetTickCount();
		cat.x -= cat.movex;
		cat.y -= cat.movey;

		if(cat.x == 0 )
		{
			cat2.x += cat2.movex;
			cat2.y += cat2.movey;
		}
		
	}

Well there is little to go on here, but....

Consider this, your cat moves from say 100 to 0., then.....
you have written cat.x -= cat.movex; which works fine until
cat.x==0.
Then you write cat2.x += cat2.movex; Fine now consider the sequence if say movex=5;

100,95...5,0,5,0,5,0.. That is because you do not change the sign of movex

you need a

if(cat.x == 0 ) {
  cat2.x += cat2.movex;
  cat2.movex*=-1;
  cat2.y+=cat2.movey; 
}

hope that helps.. if not you are going to have to post a lot more code and that is going to be difficult to get people to debug for you.

Also note: there is another deadly bug.. you have written if (cat.x==0) , what if you say start from 100 and movex == 3. Oh cat.x is NEVER 0. so you should write cat.x<=0 .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.