Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - How to implement parallax scrolling effect

Reply to topic
Author Message
  • Joined: 06 Aug 2021
  • Posts: 49
Reply with quote
How to implement parallax scrolling effect
Post Posted: Tue Aug 17, 2021 6:51 pm
Last edited by bofner on Tue Aug 17, 2021 7:51 pm; edited 1 time in total
Hey all, I'm currently just testing out different effects using devkitSMS in C, and I was wondering how you go about making a parallax effect. From what I understand you have to use line interrupts in some capacity. I'm trying to make the top 1/3 of the screen scroll slower than the bottom 2/3. I've been searching past threads, but finding my exact question has been a bit challenging. Any input or links to previous threads is greatly appreciated!

Thanks!
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14744
  • Location: London
Reply with quote
Post Posted: Tue Aug 17, 2021 7:27 pm
I don’t know exactly how it’s done in devkitSMS but the underlying pattern is:

- set up the line interrupt at some suitable number, eg 64
- in the interrupt handler, distinguish line interrupts from frame interrupts
- in the frame interrupt, set a counter to 0 and set the scroll value to the upper value
- in the line interrupt, increment the counter and if it is 1, set the scroll value to the lower value. It will then trigger a second time after another 64 lines - this time you do nothing. You can’t avoid this double triggering.

Changing the two scroll values is up to you.
  View user's profile Send private message Visit poster's website
  • Joined: 06 Aug 2021
  • Posts: 49
Reply with quote
Post Posted: Tue Aug 17, 2021 7:46 pm
Thanks, that's really helpful!

Maxim wrote

- in the interrupt handler, distinguish line interrupts from frame interrupts


What would the difference be? Is it that line interrupts are dependent on the current scanline, and frame interrupts can occur before a frame?
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14744
  • Location: London
Reply with quote
Post Posted: Tue Aug 17, 2021 10:44 pm
There’s a status register that tells you which one triggered the interrupt handler. Frame interrupts are the ones that you usually use to know when it’s VBlank time. Line interrupts only occur when you set the appropriate register.
  View user's profile Send private message Visit poster's website
  • Joined: 06 Aug 2021
  • Posts: 49
Reply with quote
Post Posted: Tue Aug 24, 2021 12:35 pm
This is quite helpful

https://www.smspower.org/forums/16281-DevkitSMSExamples
  View user's profile Send private message
  • Joined: 06 Aug 2021
  • Posts: 49
Reply with quote
Post Posted: Tue Aug 24, 2021 5:31 pm
bofner wrote
This is quite helpful

https://www.smspower.org/forums/16281-DevkitSMSExamples


Also this from sverx:

void your_handler (void) {
SMS_setBGScrollX (bottom_part_scroll);
SMS_disableLineInterrupt();
}

void main (void) {

// your setup code here

SMS_setLineInterruptHandler (your_handler);

while (true) {

// your game code here

SMS_waitForVBlank ();
SMS_setLineCounter (which_row_to_break);
SMS_enableLineInterrupt();
SMS_setBGScrollX (top_part_scroll);
}

}
  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!