Hey everyone! I'm curious how you all go about implementing sprite animations in your projects.
Personally I've taken the route of storing states for the entity in question and a timer to determine what frame should be loaded. I then go about writing logic that ultimately stores pointer values to be used by a generic sprite loading routine. A simplified excerpt from my code:
I tried replacing all that logic with lookup tables instead and got it working but started to question whether it was just making things more complicated.
Now I'm thinking about it again, though. My reasoning being that by having a generic routine for loading a frame for any given entity type and timer, I would be able to write a tool to create animations from a set of metasprites. Doing it that way might alleviate me from having to write most of the animation code (the animation state machine, I guess you would call it) for each individual sprite entity. But by doing so I guess I would also lose full control of the animations.
So, how do you guys and gals go about sprite animations? Do you write all the logic for which frame to display by hand or do take a more tricky route?
Cheers!
Personally I've taken the route of storing states for the entity in question and a timer to determine what frame should be loaded. I then go about writing logic that ultimately stores pointer values to be used by a generic sprite loading routine. A simplified excerpt from my code:
Code:
LoadPlayerSprite:
; variables:
; curr_entity_state_1 ; set before entry representing the player's state
; OAM_currSpriteAnimTimer ; set before entry and later used by the generic routine "LoadSprite"
lda curr_entity_state_1
and #PLAYER_WALKING
beq @NotWalking
lda OAM_currSpriteAnimTimer
cmp #PLAYERSPRITE_RUN_01_TIME
bcc @SetFrameToRun01
cmp #PLAYERSPRITE_RUN_02_TIME
bcc @SetFrameToRun02
cmp #PLAYERSPRITE_RUN_03_TIME
bcc @SetFrameToRun01
jmp @SetFrameToRun03
@NotWalking:
....
@SetFrameToRun01:
lda #<(playersprite1_run_01)
ldx #>(playersprite1_run_01)
jmp LoadSprite
@SetFrameToRun02:
lda #<(playersprite1_run_02)
ldx #>(playersprite1_run_02)
jmp LoadSprite
@SetFrameToRun03:
lda #<(playersprite1_run_03)
ldx #>(playersprite1_run_03)
jmp LoadSprite
....
LoadSprite:
; loads metasprite data into $0200, using a and x as pointers
I have code like this for all entities.; variables:
; curr_entity_state_1 ; set before entry representing the player's state
; OAM_currSpriteAnimTimer ; set before entry and later used by the generic routine "LoadSprite"
lda curr_entity_state_1
and #PLAYER_WALKING
beq @NotWalking
lda OAM_currSpriteAnimTimer
cmp #PLAYERSPRITE_RUN_01_TIME
bcc @SetFrameToRun01
cmp #PLAYERSPRITE_RUN_02_TIME
bcc @SetFrameToRun02
cmp #PLAYERSPRITE_RUN_03_TIME
bcc @SetFrameToRun01
jmp @SetFrameToRun03
@NotWalking:
....
@SetFrameToRun01:
lda #<(playersprite1_run_01)
ldx #>(playersprite1_run_01)
jmp LoadSprite
@SetFrameToRun02:
lda #<(playersprite1_run_02)
ldx #>(playersprite1_run_02)
jmp LoadSprite
@SetFrameToRun03:
lda #<(playersprite1_run_03)
ldx #>(playersprite1_run_03)
jmp LoadSprite
....
LoadSprite:
; loads metasprite data into $0200, using a and x as pointers
I tried replacing all that logic with lookup tables instead and got it working but started to question whether it was just making things more complicated.
Now I'm thinking about it again, though. My reasoning being that by having a generic routine for loading a frame for any given entity type and timer, I would be able to write a tool to create animations from a set of metasprites. Doing it that way might alleviate me from having to write most of the animation code (the animation state machine, I guess you would call it) for each individual sprite entity. But by doing so I guess I would also lose full control of the animations.
So, how do you guys and gals go about sprite animations? Do you write all the logic for which frame to display by hand or do take a more tricky route?
Cheers!