gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Fastest way to scroll

#31362 - QuantumDoja - Fri Dec 10, 2004 2:35 pm

Hi, I have come to the stage of my little gameboy project now where I can display a background image on the screen, from what is in memory, of course now i want to scroll..

my tiles are set up as 8 by 8.

They are drawn, by working out position from a level array, loading the correct tile, and using a plot pixel method to fill that tile space. So in effect I have 30(width) by 20(height) tiles on my screen.

Which is going to be the best method for me to draw the next screen, ie 1px -> onwards, so when as the user presses the direction it scrolls smoothly?????

Thanks
_________________
Chris Davis

#31364 - Lupin - Fri Dec 10, 2004 2:50 pm

I am not sure but i think there are 2 ways... first way is to use a 256x256 map and scroll it pixel wise (using the BG H/V offset registers) and when you advance 8 pixels you change the data of that layer so that it starts at the new tile in X or Y direction and set the pixel wise offset back to 0.

Another, and faster, way is to set up a 512x512 or whatever layer (a large one ;)) and then ONLY use the offset registers to scroll it pixel wise, but then the size for the map is limited.
_________________
Team Pokeme
My blog and PM ASM tutorials

#31368 - ScottLininger - Fri Dec 10, 2004 3:59 pm

Once you've drawn a map and made it appear (which it sounds like your have?) the scrolling part is easy. You just modify a couple of scroll registers and it works.

In your case it's extremely easy, since your 20x30tile map is small enough to fit onto a single 256x256px background. (If you maps gets bigger than the largest possible tile background, then you have to start loading tiles dynamically... that's what Lupin is talking about above.)

Anyway, here's an example:

The following assumes you are using background layer #3. There are similar registers for other backgrounds. Try the cowbite spec for a complete list of registers and what they do.

Code:

#define PADUP              !(*KEYS & KEY_UP)
#define PADDOWN            !(*KEYS & KEY_DOWN)
#define PADLEFT            !(*KEYS & KEY_LEFT)
#define PADRIGHT           !(*KEYS & KEY_RIGHT)

// use some vars to keep track of your scroll
int scrollX = 0;
int scrollY= 0;

while (1) {
   
    // this code would be ridiculously fast, but you get the idea
    if (PADUP) scrollY--;
    if (PADDOWN) scrollY++;
    if (PADRIGHT) scrollX++;
    if (PADLEFT) scrollX --;
 
    // modify those registers!
    REG_BG3HOFS = scrollX;
    REG_BG3VOFS = scrollY;

}


Cheers,

-Scott

#31507 - Cepheus - Sat Dec 11, 2004 2:55 pm

Dovoto have an example on how to scroll big maps in his gba tutorials ( http://www.thepernproject.com/English/tutorial_Making_The_Game.html ).