Hello there!
I'm programming a sidescroll game and by now I managed to move and animate the player's sprite
Now I'm working with scrolling. Suppose I have 3 backgrounds, I've got the first 2 loaded in the two name tables, now I'd like, as the scrolling goes, to load the third background (partially, not the whole at a time, just like Megaman/Rockman games) into the first name table. Is there a good example or a thread about this?
Thanks in advace!
PS: Sorry for my poor English, I'm Spanish
Well no good thread about it as far as I can remember, but looking at Mega Man games with a nametable viewer (or whathever your favourite games is) might give you the idea.
As long as you scroll in only one direction at a time this is really simple : compare the new scroll value to the old, and if it gets past a certain point write a tile column/metatile or whathever to the nametable, if possible at a position that is not visible on the screen.
When you had to make code that loads the level data on the screen how did you do this ? For my game I have a routine that write a metatile at a position on the screen, and I just call it - the only difference is that when you load the screen for the 1st time you load all the screen at once, but when you do it for scrolling you only do it one metatile at once (or one column at once, depending on how you do it), and during VBlank.
The game I'm currently developping only does fast-scrolling so it's even simpler, I just write tile blocks as I scroll and don't even have to compare scroll values (since it scrolls at constant speed). I plan to upgrade the engine for future games tough, and this time with true scrolling, the only differences is that insted of writing new meatiles each frame when fast-scrolling, it will have to write them when the new scroll value get past some "reference" values (typically each 8 pixels, or each 4 pixels or whathever you want, depend how you hold it).
If you want to do any multidirectional scrolling, it will get MUCH MUCH more complicated.
You definitely should buffer the VRAM writes. That way you can decode metatiles or any kind of compression with all the time you need, then the buffers would only contain the VRAM addresses and name/attribute data to be written during vblank.
You'll want to use the $2000 register for 2 things, one is to do VRAM increment-by-32 (for writing vertical columns to the nametable - assuming you're scrolling horizontally), and also to toggle the name table base address for every screen that you scroll (when the scroll register wraps around).
For the scroll updates there's a lot of way to do it. You could update a column of tiles (half of a 'metatile' column) for every 8 pixels you scroll, or you could just update a full metatile for every pixel that's scrolled. Or pretty much any combination of those 2 methods, just as long as it's ready by the time it's on the screen.
Yeah basically it depends on max speed you want to achieve. If you want to go very fast maybe you won't be able to do it the metatile way, and will have to decode full columns of tiles (slightly more complicated). As long as you go slow enough, writing metatiles at a time is simpler on code-side as you only decode one metatile, buffer it and write it to the PPU.
Also depends on your metatile size, I use 32x32 like Mega Man/Castlevania games, but some games are only 16x16, or even 32x16. If you use 16x16 dealing with attributes will be slightly more complicated, as you'll have to write attribute from 4 decoded metatiles. Or just go with the "lazy" read-modify-write option (with AND and OR operations), which is just as good (just remember you have to read 2 times from $2007).