![]() |
||||
|
|
||||
|
Smooth Scrolling
introduction This is a tutorial that will show you how to scroll smoothly using tiles. Basically, so the smallest scroll distance isn't the tile width. I've noticed a lot of people have been asking about this so here is a tutorial! This tutorial uses some of the BiohazrdDD Grafx Core (available from the Source Code page BTW) to do some of the mundane tasks like initializing DirectDraw. the code Basically, smooth scrolling is akin to clipping, since you have to change the RECTs of the tiles so some are only partially shown. We're not going to be using DirectDraw clipper though, we're using a custom software clipper. There isn't a speed loss, in case you are wondering :) This tutorial does assume you already know how to do Tiling, since here only very simple (read crude) tiling techniques are used. First, we set up an array of tiles (20 in total) to be displayed. Then, we have to detect the coordinates of the mouse. Here we use GetCursorPos:
Then we respond if the mouse is within the set boundaries. In this case, if the pointer is within 10 pixels of the edge we scroll.
We use two variables here, OffsetX and OffsetY. These track how many pixels we are from coordinate 0,0 on the screen. When we draw the tiles, these values are subtracted from each tiles X and Y values.
To do the blitting, we use a seperate subroutine. This is where the clipping routines actually are.
This will perform the actual clipping. Basically, when each bitmap is drawn, the routine checks whether it is outside of the screen area and then messes with the rects of the image. This was made for an 800x600 resolution, so you would have to change the two numbers (800 and 600) for another resolution. That's it for the Smooth Scrolling tutorial! You might want to Download the Source, to see the sample in action. If you have any problems with the sample ask a question on our Message Board!
|