Tuesday, January 8, 2008

"...tile please"

Night one of figuring out the background/tile scroll algorithm...I spent a few hours re-reading how the DS stores and handles background maps and tried some things, placing tiles in different background map sizes and filing different BG_MAP_RAM regions. I spied the activities with the NO$GBA debugger. I could see what was actually happening to the VRAM (video ram) and determined what I will initially try as my background tile/scroll algorithm.

I will put the DS in BG_64x64 mode, this will set the tile mode of the DS to be 64x64 tiles wide. The DS screen size is 32x24 tiles wides (256x192 pixels). So, that means I can load an image that is 512x512 pixels into the background, and if the screens left,top origin is 0,0...I'll be able to scroll 2 screen widths right before hitting the edge of my image.

Okay, all those pixels and tiles talk and 32x24, 64x64, etc...might be a little confusing, but it really isn't. The DS screen size is 32x24 tiles. I'll be using 8x8 pixel tiles. So, 32x8 = 256 pixels, and 24x8 = 192 pixels. If I set a background map size of 64x64 tiles, that is 64x8 = 512 pixels, by 512 pixels.



The above isn't close to scale, but should give you and idea of what I'm trying to describe. Imagine the bigger box as the background map, the smaller one is the screen. You see the screen can scroll a little bit before getting to the horizontal, and vertical edges. When the screen does hit those edges the screen just loops back around. Therefore, if the background image is US flag, and we start the screen in the top left corner on the stars and do a horizontal scroll, when we get to the right edge and go a pixel over the border we will begin to see the beginning of the stars again.

This would make for a very monotonous game if we continued to loop on the background, a perpetual, ground hog effect, or is it an infinite regression? I digress...so the idea behind the background/tile scrolling is when the screen hits the border, we load the unseen areas of the background (if we are on the right edge, then we load the left edge with new and different tile data), changing parts of the original image as we merrily scroll about.

Note: Next posting I will draw this, scan in, and paste to blog what I'm trying to describe. I'm a visual learner, and I suspect a lot of other folks are too.

I will stop here, because I realize that what I need to do is draw this all out by hand to show you, "Show them! You mean show yourself!" how this will work. A picture is worth 1000 words, they say. Who is the "they?"

No comments: