I did exactly the same thing a while ago. To get the background to scroll you need a bit of maths. The way I did it was to imagine the screen at the bottom of the picture and then increase the drawing coordinates each time. The tricky bit is when you get to the top of the picture and you need to draw the bottom half of the picture on the bottom half of the screen and the bottom half of the picture on the top half on the screen. To do that I used an index and then just reset it back to zero when the screen coordinates crossed the bottom of the picture (needs a bit of imagination to truely understand what I mean). I wrote this code a while ago, but it might help you/give you some ideas how to do it.
Again, exactly how you do it is up to you. I hope that you take the code posted below and learn from it rather than blindly using it. Also remember, the way I did it may not be the most efficient way this effect can be done.
Code:
/* Add Background to the screen buffer - Code more complex because of scrolling */
cindex.background_index0 = static_cast<int>( (cgraphics.GetCurrentBackground()->h - SCREEN_DIMY)/SCROLL_RATE);
if( cindex.background_index <= cindex.background_index0 )
{
/* Draw Image as normal */
blit(cgraphics.GetCurrentBackground(), cgraphics.GetScreenBuffer(), 0,
static_cast<int>( cgraphics.GetCurrentBackground()->h - SCREEN_DIMY - (SCROLL_RATE*cindex.background_index) ),
0,0,SCREEN_DIMX, SCREEN_DIMY);
}
if( cindex.background_index > cindex.background_index0 )
{
/* Draw bottom 1/2 of image on top 1/2 of screen */
blit(cgraphics.GetCurrentBackground(), cgraphics.GetScreenBuffer(), 0,
static_cast<int>(cgraphics.GetCurrentBackground()->h - (SCROLL_RATE*(cindex.background_index - cindex.background_index0))),0,0,
cgraphics.GetCurrentBackground()->w, static_cast<int>((cindex.background_index - cindex.background_index0)*SCROLL_RATE));
/* Draw top 1/2 of image on bottom 1/2 of screen */
blit(cgraphics.GetCurrentBackground(), cgraphics.GetScreenBuffer(), 0, 0,0, static_cast<int>((cindex.background_index - cindex.background_index0)*SCROLL_RATE),
cgraphics.GetCurrentBackground()->w, static_cast<int>(SCREEN_DIMY - ((cindex.background_index - cindex.background_index0)*SCROLL_RATE)));
if( SCROLL_RATE*(cindex.background_index - cindex.background_index0) >= SCREEN_DIMY )
{
/* Reset background_index */
cindex.background_index = 0;
}
}
And then at the end of the screen rendering section you need something like:
Code:
/* Update the graphical indicies */
cindex.background_index++;