By the way, you only have to set the Y component to $EF-FF, you don't have to set the whole unused sprite memory to it. For example, if you're done generating sprites for the frame and need to erase the rest of it, you can just write every 4th byte in the remaining space (i.e. the Y component) to hide them. The other 3 components to each sprite don't really matter in this case, once it's offscreen, it's offscreen.
Code: Select all
ClearMem: ; Clear internal memory LDA #$FF STA $0200, x ; Set sprite memory to #$FF to render sprites off screen LDA #$00 STA $0000, x ; Clear Zero Page STA $0100, x ; Clear Stack STA $0300, x STA $0400, x STA $0500, x STA $0600, x STA $0700, x DEX CPX #$00 BNE ClearMem
L R L R STOP & DASH & UP & TALK Ijou nashi
Coordinates is fine. Edit: Well... I guess you do still need to add the width or height of the sprite to the coordinates so that going off each side is symmetrical.Next I'll be adding boundaries for the player's sprite so it won't screen wrap (should I just check coordinates or use hitbox?)
For the right and bottom of the screen, add to the sprite's position. If the carry ends up set (adding 1 to 255 would wrap to 0 and set the carry), don't draw the sprite that frame and destroy the object.Though, I don't know how to make the sprite leave the screen smoothly.
For the top/left of the screen, subtract from the sprite's position. If the carry ends up clear, don't draw the sprite that frame and destroy the object.
Edit: With scrolling or other things that make detecting offscreen more complicated, the above alone can't be used by itself. But that should give you an idea of how to move things offscreen.
You cannot easily make the sprite visually leave smoothly from the top of the screen. The topmost coordinate you can supply is 0, and that still draws the entire sprite. Offscreen = not drawn at all, so all 8 pixels of the sprite would disappear in a frame when leaving from the top.
For the left of the screen, you can mask out the left most 8 pixels of sprites and the background with $2001. This means 0, the leftmost coordinate, is a fully masked sprite. 1 is the rightmost column of pixels in the sprite is drawn, the rest of it is not. Edit: Note that this just kind of makes the leftmost eight pixels a "border" with your background color for sprites to disappear into. The border still occupies screen space.
So... yes, it's a limitation, but only for twoish sides .
The CPX #$00 is redundant. Most instructions that change a value will set the zero flag if the result is zero, so the DEX instruction will set you up for BNE/BEQ already. It is very rare that you would ever need to explicitly compare against zero.Tsutarja wrote:
Code: Select all
DEX CPX #$00 BNE ClearMem