How does this background scrolling code work? I'm glad that this code does exactly what I wanted it to do...But I can't make sense of it although I wrote it from scratch myself. What I wanted to do was create an infinitely scrolling background. What I figured I'd need to do was have it draw the entire background twice so that the second one comes in after the first one, and when the first one gets to the end it starts over behind the second one, and it would loop like this forever. However, after I wrote the code to make it scroll and tested it, it scrolls infinitely by just having the code draw the background once... I have the function to draw the background like so... void drawBackground(int xStart,int yStart,SDL Rect clip) int x,y for(y yStart y lt SCREENH y y TILEH) for(x xStart x lt SCREENW x x TILEW) drawClip(x,y,background, amp clip 45 ) And then I use the function like this to scroll the background... bgX 1 if(bgX SCREENW) bgX 0 bgY 1 if(bgY SCREENH) bgY 0 drawBackground(bgX, bgY, bgClip) It works perfectly...I just don't understand what makes it loop around with no gaps.