It is currently Mon Oct 16, 2017 7:11 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 32 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Parallax scrolling
PostPosted: Sat Aug 08, 2015 3:11 pm 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1389
I tried to do parallax scrolling in my program. I wanted to use the sprite 0 for this to change the scrolling position mid-frame.

If I have two layers that scroll with a different speed, everything works fine.

But I need at least three layers:
1. The status bar (no scrolling).
2. The background (slow scrolling).
3. The foreground (quick scrolling).

My attempt was this:
First, I do the general status bar stuff: Setting scrolling to 0, waiting for sprite 0 to hit, then setting the actual scrolling position. This works as always.

But now my problem:
For three layers, I did this:
I waited for sprite 0 to hit to change the scrolling position from 0 to the current value.
Then I moved sprite 0 down the screen to the next location.
I waited for it to hit again to change the scrolling position a second time.

But the program just took layer 1 (the status bar) and layer 2 (the background) and set it to scroll position 0.

So, I'm able to scroll with two different layers. But as soon as I try three layers, he treats the first two layers as one.

Is there any general thing that I have overlooked?

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
 Post subject: Re: Parallax scrolling
PostPosted: Sat Aug 08, 2015 3:14 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19084
Location: NE Indiana, USA (NTSC)
Only one sprite 0 hit is possible per frame. If you put the status bar on the top, you can use the 9 sprites for the first split (at the top of the status bar) and sprite 0 for the second (at the dividing line between the background and foreground). But if you do more than one split, you'll be spending a lot of time sitting in a loop. At that point, it's wise to use more advanced techniques, such as mapper IRQs or the DPCM Split.


Top
 Profile  
 
 Post subject: Re: Parallax scrolling
PostPosted: Sat Aug 08, 2015 3:31 pm 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1389
tepples wrote:
If you put the status bar on the top, you can use the 9 sprites for the first split (at the top of the status bar) and sprite 0 for the second (at the dividing line between the background and foreground).

I didn't understand this. What nine sprites are you talking about?

tepples wrote:
At that point, it's wise to use more advanced techniques, such as mapper IRQs or the DPCM Split.

Is any of this possible with simple mapper 0 games or do you need a higher mapper to do it?

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
 Post subject: Re: Parallax scrolling
PostPosted: Sat Aug 08, 2015 3:41 pm 
Offline
User avatar

Joined: Wed Apr 02, 2008 2:09 pm
Posts: 1019
Quote:
I didn't understand this. What nine sprites are you talking about?

In addition to sprite 0 hit, there's another bit that in $2002 that tells you if more than 8 sprites per scanline were drawn. You can force that to trigger during a specific part of the screen by putting 9 sprites there.

Quote:
Is any of this possible with simple mapper 0 games or do you need a higher mapper to do it?

There's possible, and there's maintainable. You could do it all solely with timed code, but that's kind of nuts. I'd recommend a mapper if you want two or more splits.

_________________
https://kasumi.itch.io/indivisible


Top
 Profile  
 
 Post subject: Re: Parallax scrolling
PostPosted: Sat Aug 08, 2015 3:49 pm 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1389
Kasumi wrote:
In addition to sprite 0 hit, there's another bit that in $2002 that tells you if more than 8 sprites per scanline were drawn. You can force that to trigger during a specific part of the screen by putting 9 sprites there.

I assume this works only once per frame, right? Because otherwise I would think that you can use this to do as many scroll splits as you like.

Kasumi wrote:
You could do it all solely with timed code, but that's kind of nuts. I'd recommend a mapper if you want two or more splits.

Well, in this case, I'll go with one split and try out the nine sprites version. Because I'm not planning on doing my first game with a higher mapper or with any big fancy tricks.

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
 Post subject: Re: Parallax scrolling
PostPosted: Sat Aug 08, 2015 3:58 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 1768
Location: DIGDUG
Use a scanline IRQ, you'll waste less time looping waiting for screen splits.

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
 Post subject: Re: Parallax scrolling
PostPosted: Sat Aug 08, 2015 4:07 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10045
Location: Rio de Janeiro - Brazil
Another option (if you don't want to lose 10 sprites), is to use timed code for the status bar. In the NMI, do your PPU updates normally, and when you're done, you wait for the sprite 0 hit flag (which was set in the previous frame) to be cleared, which happens at the end of VBlank, to sync with the PPU. Then you run a dummy loop that always takes X scanlines to finish, where X is the height of the status bar. Now you can do the first split, and the next one is done after the sprite 0 hit, as you already got working.

The downside is the amount of CPU time you spend just waiting, after VBlank and before the first split. To minimize this loss you could try to put some tasks that use a fixed amount of CPU cycles in there, such as reading controllers, clearing OAM, or whatever other tasks that always take the same time to run. Then pad until the end of the status bar.


Last edited by tokumaru on Sat Aug 08, 2015 4:09 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Parallax scrolling
PostPosted: Sat Aug 08, 2015 4:09 pm 
Offline
User avatar

Joined: Wed Apr 02, 2008 2:09 pm
Posts: 1019
DRW wrote:
I assume this works only once per frame, right? Because otherwise I would think that you can use this to do as many scroll splits as you like.

To be honest, I don't know if it works only once for frame.

When you use sprite DMA, it COPIES the page you give it (say $0200-$02FF) to the PPU. If you write a new value anywhere in that range, it doesn't matter. The PPU wouldn't see it until you sprite DMA again. Because the PPU doesn't look at $0200-$02FF when it's rendering. It looks at its own internal RAM which you can't really access. (Please no pedantic, guys.) You can't sprite DMA while the screen is rendering safely, so the whatever sprites you gave it are what is drawn. You can't move them mid render to get multiple hits. That would at least be why sprite 0 doesn't work multiple times.

It'd be interesting to know if the 9 sprites can hit multiple times per frame, but you could only get 7 splits that way using ALL of your sprites for only that purpose. 64/9=7 and some decimals.

Edit: One other thing to keep in mind if it IS possible to do multiple times, is the action on screen (your actual enemies/projectiles/player character) might cause a sprite overflow which would screw up your splits. This is why tepples recommended the overflow for the status bar split (It's easy to keep your game objects from going there), and sprite 0 for the extra split.

_________________
https://kasumi.itch.io/indivisible


Top
 Profile  
 
 Post subject: Re: Parallax scrolling
PostPosted: Sat Aug 08, 2015 4:41 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10045
Location: Rio de Janeiro - Brazil
Yes, the sprite 0 hit and sprite overflow flags only work once per frame, because once they're set by the PPU, you can't manually clear them. The PPU will automatically clear them at eh end of VBlank.

But even if you could reuse the sprite overflow flag for multiple splits, that would be dangerous, since you can have accidental overflows as the game objects move around the screen. This is why this solution was suggested for a status bar at the top of the screen, because the status bar is rendered before the game objects, so you can be sure there will be no sprite overflows before the status bar ends. You can't use this flag reliably at the bottom of the screen.


Top
 Profile  
 
 Post subject: Re: Parallax scrolling
PostPosted: Sat Aug 08, 2015 4:53 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 1768
Location: DIGDUG
Another thought... If your upper background is a repeating pattern, you could swap CHR-ROM banks to shift the pattern at a different rate than the lower background.

I think Bucky O'Hare does this somewhere.

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
 Post subject: Re: Parallax scrolling
PostPosted: Sat Aug 08, 2015 5:00 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 1768
Location: DIGDUG
And Battletoads, and Blade Buster, etc.

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
 Post subject: Re: Parallax scrolling
PostPosted: Sat Aug 08, 2015 5:17 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10045
Location: Rio de Janeiro - Brazil
dougeff wrote:
And Battletoads, and Blade Buster, etc.

And Sword Master, and Metal Storm, and Mitsume ga Tooru... BTW, Battletoads doesn't use bankswitching, it uses CHR-RAM and manually updates the tiles. That's hardcore.

Anyway, unless you use CHR-RAM and do it like Battletoads (which is pretty hardcore), you have to use a complex mapper, which he doesn't want to.


Top
 Profile  
 
 Post subject: Re: Parallax scrolling
PostPosted: Sat Aug 08, 2015 5:35 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 1768
Location: DIGDUG
Why did some games try to do everything with CHR-RAM? Were the ROM chips cheaper?

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
 Post subject: Re: Parallax scrolling
PostPosted: Sat Aug 08, 2015 6:03 pm 
Offline
User avatar

Joined: Wed Dec 06, 2006 8:18 pm
Posts: 2799
Using CHR-RAM instead of CHR-ROM probably did result in a lower production cost. But certain things particularly with more advanced mappers are better suited to CHR-ROM. And the reverse is true, CHR-RAM is better suited for certain things too.


Top
 Profile  
 
 Post subject: Re: Parallax scrolling
PostPosted: Sat Aug 08, 2015 6:26 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6272
Location: Seattle
Yes, ROM was (and still is) cheaper.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 32 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: Google [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group