Jump to content
  • Advertisement
Sign in to follow this  
SomeoneX

Problem with surface blitting

This topic is 3716 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

I'm using SDL. The menu surface isn't blitting in my code, so all I have is a blank screen that I have to kill the process of, because I haven't put in code so you can "X" out of it. I have narrowed it down to the function that is causing the problem. I have tried using different coordinates, but still nothing. Do I need a while(&event) loop? Although that comes after the problem. Anyways, here's the relevant bits of code. The problematic function
void startMenu()
{
	int choice = 1;
	
	blitSurface(220, 160, menu, screen);
	
	while(true)
	{
		if(event.type == SDL_KEYDOWN)
		{
				if(event.key.keysym.sym == SDLK_UP)
				{
					choice++;
					if(choice > 3)
					{
						choice = 1;
					}
				}
				else if(event.key.keysym.sym == SDLK_DOWN)
				{
					choice--;
					if(choice < 1)
					{
						choice = 3;
					}
				}
				else if(event.key.keysym.sym == SDLK_RETURN)
				{
					break;
				}
		}
		
		//redraw menu
	}
	
	switch(choice)
	{
		case 1:
			//gameStart();
			break;
		
		case 2:
			//gameOptions();
			break;
			
		case 3:
			//menuQuit();
			break;
	}
}

and blitSurface(), because there's always the chance it's been written wrong
[source lang="cpp]
void blitSurface(int x, int y, SDL_Surface *foreground, SDL_Surface *background, COLOR color = NONE)
{
	SDL_Rect position;
	SDL_Rect clip;
	
	position.x = x;
	position.y = y;
	
	if(color != NONE)
	{
		clip.x = 0;
		clip.y = color * 32;
		clip.w = 32;
		clip.h = 32;
		
		SDL_BlitSurface(foreground, &clip, background, &position);
	}
	else
	{
		SDL_BlitSurface(foreground, NULL, background, &position);
	}
}

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!