Page 1 of 1
SGDK - scrolling a background in sections
Posted: Sat Mar 10, 2012 3:04 am
by djcouchycouch
Hi,
One thing I haven't been able to wrap my head around is how to make it so that I can scroll a background plane at different speeds. The effect I'm most interested in is how the background scrolls in Sonic The Hedgehog 1. The far off mountains, the waterfalls and the ocean scroll at different rates. And the ocean scrolls at the pixel level.
How would I go and do that?
Thanks!
DJCC
Posted: Sat Mar 10, 2012 6:57 pm
by Chilly Willy
Set the horizontal scroll mode to per line, then the hscroll table has a scroll value for every line on the display. Then set different lines to different values to scroll them at different speeds.
Posted: Sat Mar 10, 2012 7:38 pm
by djcouchycouch
That was just enough information to get me going, thanks!
I'm relying on SGDK since I'm not very familiar with the Genesis hardware, and there wasn't any obvious way (to me anyway) to set the scroll mode. But then I read that those settings are based on register values. SGDK doesn't seem to expose a function to set the scroll mode explicitly, but it does have a VPD_setReg() function. So I managed to find which register the scroll mode corresponds to, 0x0B, find the right value to set and call VDP_setReg() with them. Great!
Posted: Sat Mar 10, 2012 10:49 pm
by Chilly Willy
There's a functon to set the hscroll value for a line:
Code: Select all
void VDP_setHorizontalScroll(u16 plan, u16 line, u16 value);
You tell it the plane (A or B), the line number, and the scroll value.
Posted: Sun Mar 11, 2012 1:18 am
by djcouchycouch
Yes, exactly. That's what I was using.

But I didn't know how to enable the scrolling mode so it didn't do anything. But everything is working now.
Posted: Thu May 09, 2013 11:36 am
by POLYGAMe
Chilly Willy wrote:Set the horizontal scroll mode to per line, then the hscroll table has a scroll value for every line on the display. Then set different lines to different values to scroll them at different speeds.
If it's done per line, is this how you'd go about doing an outrun style game? Ie, manipulate the "lines" of the road for corners? I guess hills and some form of graphical effect to display speed would be other issues...
Posted: Thu May 09, 2013 11:37 am
by POLYGAMe
djcouchycouch wrote:Yes, exactly. That's what I was using.

But I didn't know how to enable the scrolling mode so it didn't do anything. But everything is working now.
Just to be clear, did you just set up the scrolling, as above and enable it and it scrolls? Sounds quite simple

Posted: Thu May 09, 2013 3:52 pm
by Mask of Destiny
POLYGAMe wrote:Chilly Willy wrote:Set the horizontal scroll mode to per line, then the hscroll table has a scroll value for every line on the display. Then set different lines to different values to scroll them at different speeds.
If it's done per line, is this how you'd go about doing an outrun style game? Ie, manipulate the "lines" of the road for corners? I guess hills and some form of graphical effect to display speed would be other issues...
I haven't actually pulled one of those games apart, but I believe that's how its done. Line scrolling for making the road bend. Palette cycling (and maybe some tile animation) to animate the road/ground to create the illusion of movement. Sprites for things like trees and signs
Posted: Thu May 09, 2013 10:23 pm
by POLYGAMe
Mask of Destiny wrote:POLYGAMe wrote:Chilly Willy wrote:Set the horizontal scroll mode to per line, then the hscroll table has a scroll value for every line on the display. Then set different lines to different values to scroll them at different speeds.
If it's done per line, is this how you'd go about doing an outrun style game? Ie, manipulate the "lines" of the road for corners? I guess hills and some form of graphical effect to display speed would be other issues...
I haven't actually pulled one of those games apart, but I believe that's how its done. Line scrolling for making the road bend. Palette cycling (and maybe some tile animation) to animate the road/ground to create the illusion of movement. Sprites for things like trees and signs
Awesome. I might have to give it a go. I built a 2.5D racing engine in unity... Uses same theory but manipulating quads, instead of lines of pixels. Works well

Posted: Fri May 10, 2013 1:03 am
by Chilly Willy
Remember that scrolling on the MD allows for horizontal scrolling on the whole screen, each line of tiles, or every line, and vertical scrolling on the whole screen, or groups of two tiles. A great example of scrolling in both directions by a variable amount across the screen is the underwater parts of Earthworm Jim.
Posted: Sun May 12, 2013 7:29 am
by TechnoZealot
I've been trying this out a bit, and I'm curious, what is the best way, (or any way at all franly that works

) to buffer up new tiles when scrolling?
This is something I have not been able to figure out.
(Also it seems like the VDP has an extra screen vertically and half of a screen horizontally unallocated when scrolling in either direction.)
Posted: Sun May 12, 2013 8:41 am
by Stef
You never refresh the whole screen, only the "diff" part (difference between new and old frame), and you do that "ahead" generally as the virtual screen is bigger than display screen. When you have only horizontal scrolling but in both way, it may be more convenient to use the 128x32 tilemap size so you can keep up to 3 screens in vram. Generally you try to keep as much tiles you can in vram to avoid tile refresh (except for sprite) during a singe level. At some point you can refresh some tiles for very large level but you have to use a nice method to divide you tile upload on several frame.
Posted: Sun May 12, 2013 8:57 am
by POLYGAMe
This all sounds so confusing. Luckily my first game doesn't scroll
