This is the generic animation code I used in the VLDC9 overworld sprites, just drop it somewhere in the sprite's main code where it runs every frame the GFX routine does. One such place would be right before the graphics routine JSR.
Code!animationtimer = $163E
;timer used for the animation. has to be a self-decrementing table
!animationframe = $1602
;which frame to display right now. non-decrementing table
!frametime = $0A
;how many smw frames each sprite frame should show
!frames = $03
;how many animation frames there are
;timer logic
LDA !animationtimer,x
BNE .NoTimerSet
LDA #!frametime
STA !animationtimer,x
LDA !animationframe,x
INC
CMP #!frames
BCC .NoFrameReset
LDA #$00
.NoFrameReset
STA !animationframe,x
.NoTimerSet
Then you can just use
LDA !animationframe,x in your graphics routine and use that to access the tables, assuming X still has the sprite slot. If not then work around that by temporarily storing the
!animationframe into scratch RAM before overwriting X.
If you want each frame to show for different amounts of times, there's also this routine here that I made for a few of the overworld sprites (like the Haunted World Crow and the Lava Lotus).
Just throw that in on its own somewhere and
JSR Animations right before the JSR to the graphics routine, simpler that way.
Check the bottom of the code for each frame's individual length. Table has to end in a lonely #$FF so the game knows when to restart the table.
Code!animationtimer = $163E
;timer used for the animation. has to be a self-decrementing table
!animationframe = $1602
;which frame to display right now. non-decrementing table
Animations:
;check if current frame's timer is up
LDA !animationtimer,x
BNE .NoNewFrame
;if so, increase the frame number
INC !animationframe,x
.Repeat
;load the frame's length and store it to the timer
LDA !animationframe,x
TAX
LDA .AnimationSpeeds,x
LDX $15E9 ;reload sprite index
CMP #$FF
BNE .StoreFrameTime
;when FF is reached, set frame to 0 and reload time
STZ !animationframe,x
BRA .Repeat
.StoreFrameTime
STA !animationtimer,x
.NoNewFrame
RTS
.AnimationSpeeds
db $B8,$0B,$0B,$0B,$0B,$0B,$0B,$0B,$0B,$28
db $FF
;this table is just an example, it's what my lava lotus overworld sprite uses
Your layout has been removed.