How come second picture blits ok, but not the first pic [SDL]

Hello. I am using SDL. I'm here because asking about SDL related
stuff because responses on the SDL forum seem to take weeks and
I am sure there are some here that have used SDL.

I am using an if/else statement to blit two different pictures. It goes like so,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
void startupLoop()
{
    int x;
    int y;

    if(event.type == SDL_MOUSEMOTION)
    {
        x = event.motion.x;
        y = event.motion.y;

        //First Picture
        if((x > 100 & x < 180) && (y > 200 && y < 260))
        {
            SDL_BlitSurface(homeScreenPlay, NULL, screen, NULL);
        }
        
        //this is the original that will be blitted if the mouse rolls out of bounds
        else
            SDL_BlitSurface(homeScreen, NULL, screen, NULL);



        //Second Picture
        //If I take out this if/else statement below, the first picture will blit
        if((x > 400 && x < 480) && (y > 200 && y < 260))
        {
            SDL_BlitSurface(homeScreenExit, NULL, screen, NULL);
        }
        
        //this is the original that will be blitted if the mouse rolls out of bounds
        else
            SDL_BlitSurface(homeScreen, NULL, screen, NULL);
    }
}


My problem is the second picture will blit, but not the first. And if
delete the second if else statement with the second picture in it then
the first picture will blit??? Is my problem SDL or c++ related? Thanks
for any response.
I think you blit the second image on top of the first image so that you cannot see the first image.
Thanks for your response. When I get back in the bounds that triggers my first picture, shouldn't the first picture blit back over the second picture. If the second is blitting over the first picture, is there a way I can get the first picture back on top of the second. Thanks again.
EDIT: It's actually homeScreen (line 32) that is blitted on top of the first image.

If you only want one image to be blitted you can use else-if like this:
1
2
3
4
5
6
7
8
9
10
if((x > 100 & x < 180) && (y > 200 && y < 260))
{
	SDL_BlitSurface(homeScreenPlay, NULL, screen, NULL);
}
else if((x > 400 && x < 480) && (y > 200 && y < 260))
{
	SDL_BlitSurface(homeScreenExit, NULL, screen, NULL);
}
else
	SDL_BlitSurface(homeScreen, NULL, screen, NULL);
Last edited on
Works! Just when I think I understand if/else's....Thanks sooo much!

One more question. Is it alright to post SDL related stuff on this forum?
Last edited on
Topic archived. No new replies allowed.