Originally posted by: brilliancenp
Ok so this is an old thread I know, I have been going through the tutorials and have everything working except updating the score. I didn't see this explained anywhere but the comments say to update using background tiles or lots of sprites. I would figure updating using background tiles is best since the background tile numbers correspond to the numbers so '0' = $00 '1' = $01 and so on. The problem I am having is updating the background sprites. I can t seem to figure out how to do it and searching google I cant find an answer. Anyone have an example? I would figure I would need to update the background table which I can do (I think) but how to push it to the ppu correctly. Any help would be greatly appreciated.
The best way is to write it to a buffer to where it writes all your background updates in a single frame, but I won't confuse you with that just yet until you get your bearings a little more.
Basically, somewhere in the vblank (which is typically at the beginning of NMI), you have to update the background tiles. The code will look something like this:
UpdateBackgroundTile:
LDA $2002 ;wake up PPU and let it know we are about to update stuff
LDA #$20 ;this is the hi byte of the address you're writing to. so if the nametable tile you're updating is located at $2084, $20 is the hi byte.
STA $2006
LDA #$84 ;this is the low byte of the address you're writing to. I kept the same address example that I used above.
STA $2006
LDA #$xx ;this is the tile number of the new tile you are writing to the address you described above.
STA $2007 ;write the tile
RTS
Now, doing it this way is fine, but you have to understand that unless you have a flag telling it to only do it once, it's going to re-draw this tile every single frame until you tell it otherwise. And when you start developing a bigger game, you won't get far before updates like this prevent you from expanding, because vblank is a treasured commodity.
Let us know if you need further clarification, or when you're ready for more advanced solutions.
Homework is to read this:
https://wiki.nesdev.com/w/index.p...
You don't need to understand the technical details of what it's doing, but at least try to give it a read and understand the concepts. We'll get there. One step at a time!
Also, welcome to NintendoAge!