I add my score for spites.
So I just do a simple scroll.When your X position is bigger than #$C0,you move right screen move right, But then if you move back (left),screen move left too.
I had added two maps at $2000 and $2400.
And made mir=1
But I don't know how to do scroll.
I tried some thimes.But when screen is moveing,it shook up and down badly.And my screen's scroll didn't work well with my sprites.
Who can help me ,tell me the main way to do a scroll?
My code is
Code:
scroll:
lda spr_x
cmp #$C0
bcs r_scroll
rts
r_scroll
lda spr_x
cmp spr_x_old
beq r_scroll_out
bcs r_scroll_r
r_scroll_l
sec
lda var
sbc movespeed
sta var
lda var
sta $2005
lda $00
sta $2005
rts
r_scroll_r
ldx movespeed
lda var1,x
sta var1
lda var1
sta $2005
lda $00
sta $2005
r_scroll_out
rts
Forgot to say:I do it in the NMI.
Hm, I don't see anything wrong with that code there. Are you running it before the STA $2006 in NMI? Try doing that.
Also when you scroll, you'll need to add/subtract the movespeed from all the (non-player) moving sprites too.
About your code : to set your vertical scrooling to $00 do "lda #$00" and not "lda $00" otherwise the value of the byte $00 in the ram will be strored as the vertical scrooling.
Oh! I didn't see that. Typo bugs are the worst.
Where would I put "lda #$00 , sta $2006 , sta $2006" ?
When I write PPU in NMI,screen will shake.If I write "lda #$00 , sta $2006 , sta $2006",screen will display well.
But where would I write these code?If I take them to different palce,screen will shake sometimes.
After write PPU every time or just write once in NMI?
If just once in NMI,where should it be?
And how to write PPU? IS screen turning off needed?We write ppu is:
Turn screen off, write ppu , #$0 to $2006 twice, turn screen on.Yes?
I want to know a normatilve way.
Thank you.
You can put the $2006 writes wherever it works, as long as it's after all the PPU writes. Screen jumping would mean it's done too late (vblank is complete, the screen is already being rendered, setting it to zero resets the screen rendering in regards to scrolling).
You don't really need to turn the screen off during vblank, because the screen is already off during vblank (PPU stops reading it's memory). Many people write zero to $2001 in the NMI anyways. I think it's a safety precaution, and I usually do that myself, in case the NMI code runs too long. Because if the screen is on while the PPU is written to, the memory can be corrupted. If the screen is forced off, it would only shake during that frame instead.