Sign in to follow this  
SomeoneX

Problem with surface blitting

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this