Sign in to follow this  
Mr_Threepwood

SDL and nested loops

Recommended Posts

Hello, I've got a problem trying to draw things to the screen when I have a nested loop:

void gameboard::drawBoard(){

    apply_surface (0,0,background,screen);


    //Loop through the array of boardslots and draw the pegs
    for (int x=0; x < 6;x++){

        for (int y=0; y <  7 ;y++){

 // stuff will go here when I can get background to display with loops


        }

    }

}
Here's apply_surface
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
{
    //Holds offsets
    SDL_Rect offset;

    //Get offsets

    offset.y = y;

    //Blit
    SDL_BlitSurface( source, clip, destination, &offset );
}
The problem I'm having is that the background won't get displayed when I have the second loop. If I comment out the loop then the background will show up. For now I've also commented out the drawing of the pegs since I'd rather deal with the background issue first. In main I call drawBoard on my gameboard object every time it goes through the main game loop. I then use SDL_Flip on my screen pointer. Why would the second loop cause a problem (I've tried the trivial stuff like changing the variable name)?

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