SGDK - scrolling a background in sections

SGDK only sub forum

Moderator: Stef

Post Reply
djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

SGDK - scrolling a background in sections

Post by djcouchycouch » Sat Mar 10, 2012 3:04 am

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

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Sat Mar 10, 2012 6:57 pm

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.

djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Sat Mar 10, 2012 7:38 pm

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!

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Sat Mar 10, 2012 10:49 pm

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.

djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Sun Mar 11, 2012 1:18 am

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.

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Post by POLYGAMe » Thu May 09, 2013 11:36 am

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...

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Post by POLYGAMe » Thu May 09, 2013 11:37 am

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 :D

Mask of Destiny
Very interested
Posts: 616
Joined: Thu Nov 30, 2006 6:30 am

Post by Mask of Destiny » Thu May 09, 2013 3:52 pm

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

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Post by POLYGAMe » Thu May 09, 2013 10:23 pm

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 :)

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Fri May 10, 2013 1:03 am

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.

TechnoZealot
Interested
Posts: 30
Joined: Mon May 06, 2013 2:27 am
Location: Vermont, USA

Post by TechnoZealot » Sun May 12, 2013 7:29 am

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 :P) 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.)

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Sun May 12, 2013 8:41 am

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.

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Post by POLYGAMe » Sun May 12, 2013 8:57 am

This all sounds so confusing. Luckily my first game doesn't scroll :D

Post Reply