• Advertisement
Sign in to follow this  

SDL and nested loops

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

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
Advertisement
Sign in to follow this  

  • Advertisement