• Advertisement
Sign in to follow this  

C++ SDL switch not working properly

This topic is 1686 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can anyone spot an error in this small code section?, when I separate it up and manual enter the coords for .x and .y it works fine, but as the clipboard size is likely to grow by quite a bit, I wanted to automate the loading process.

The error I am getting is that when Blit-ing a clip that's loaded in the for loop - its coming up blank. my loaded graphic (clipboard) has 7 images across and 4 images down, each image is 30 pixels across.

anyway the code :

void Player1::Set_CLips()
{
	int i,n;
	
	for (i=0; i < totalFrames; i++)
	{
		  switch(i)
        {
		  case 0: case 1: case 2: case 3: case 4: case 5: case 6:
		  	  CLip[i].x = (i * 30);
			  CLip[i].y = 0;
			  CLip[i].h = 30;
			  CLip[i].y = 30;
			  break;
		  case 7:case 8:case 9:case 10:case 11:case 12:case 13:
			n = i-7;
			  CLip[i].x = (n * 30);
			  CLip[i].y = 31;
			  CLip[i].h = 30;
			  CLip[i].y = 30;
			 break;
		  case 14:case 15:case 16: case 17:case 18:case 19:case 20:
			  n = i - 14;
			  CLip[i].x = (n * 30);
			  CLip[i].y = 61;
			  CLip[i].h = 30;
			  CLip[i].y = 30;
			  break;
		  case 21:case 22:case 23:case 24:case 25:case 26:case 27:
			  n = i - 21;
			  CLip[i].x = (n * 30);
			  CLip[i].y = 91;
			  CLip[i].h = 30;
			  CLip[i].y = 30;
			 break;    
		}
	}


}

Share this post


Link to post
Share on other sites
Advertisement

You have CLip.y twice, not sure if that is your problem but you should fix that.

Edited by Crusable

Share this post


Link to post
Share on other sites

Crusable, you sir are a genius with the eyesight of the hawk, I have been looking at that code for hours and couldn't see the wood for the trees.. lol, yes, that was a stupid error on my part.. should have been .w for width .

 

Cheers buddy.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement