I know how sprites work (Ycoor, TileID, Pal/Rot, Xcoor), and how to get them to the screen.
Most tutorials and documents tell you how to handle sprites, but there is very little information when it comes to game logic, in coding a sprite engine.
Most games are not a singe 8x8 sprite tile. Characters and enemies are made up of a bunch of 8x8 sprite tiles. This is where it becomes difficult for me.
Let's say I have this routine, which is only executed once when the player object is created:
; initialize player object
lda #$60
sta player_xpos
lda #$50
sta player_ypos
; simply set the player's x and y position on the screen
Simple enough, right?
I know how to draw all of the sprites for the player, but I don't know how to do it in the most efficient way. So far, most of the ways I have done it, use up a ton of code.
Let's say my player objects consists of 9 sprite tiles (Megaman, for example, while he is standing, is 9 8x8 sprite tiles)
I have this routine, which is executed every frame:
; player handler
; draw player - method 1
; The X and Y coordinates are the center origin of the player, so that if the player has to be mirrored, he'll be mirrored smoothly
; ***
; ***
; ***
; These asterisks represent the 9 8x8 sprite tiles
; One way I have done it, is start in the middle, and draw from there
; ***
; *+*
; ***
So, the plus sign represents the x and y position
[CODE]
lda player_ypos
sbc #$08
sta $200
; store the y for the first tile
lda player_xpos
sbc #$08
sta $203
; store the x for the first tile
; Then draw the tile and pal/rot values
lda #$00
sta $201
lda #$00
sta $202
When ROM hacking, I've seen games keep a table of the tile ID and pal/rot value right next to each other, so I tried programming that way too. That way seems very difficult as well. I'm manually programming every single sprite to the screen. There has to be a more efficient way of doing things. I just can't wrap my head around the logic.
Mirroring is a pain, because depending on which direction (left or right) the sprite is facing, the tiles that were supposed to be on the left side, now have to be on the right, but the middle can stay the same.
There are a few different ways that I have used to get a player sprite to appear, but the coding is intensive. Is there a way to efficiently create a sprite engine, so that no matter what sprite you want to display, you can display all of the tiles, and correctly depending on the mirroring?
I have even tried making the xpos and ypos the top-left corner of the player, but then when it comes time to mirroring, it doesn't look right. Unless I were to simply change the x/y positions when mirroring occurs.
I'm going to do some more studying of ROMs to see how the sprite engines are handled, but if anyone has any suggestions, that would be of great help.
Thanks.