|
ForumsSega Master System / Mark III / Game GearSG-1000 / SC-3000 / SF-7000 / OMV |
Home - Forums - Games - Scans - Maps - Cheats - Credits Music - Videos - Development - Hacks - Translations - Homebrew |
Author | Message |
---|---|
|
How to implement parallax scrolling effect
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! |
|
|
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. |
|
|
Posted: Tue Aug 17, 2021 7:46 pm |
Thanks, that's really helpful!
What would the difference be? Is it that line interrupts are dependent on the current scanline, and frame interrupts can occur before a frame? |
|
|
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. | |
|
Posted: Tue Aug 24, 2021 12:35 pm |
This is quite helpful
https://www.smspower.org/forums/16281-DevkitSMSExamples |
|
|
Posted: Tue Aug 24, 2021 5:31 pm |
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); } } |
|