I'm working on a simple sprite animation system and I'm not sure the best way to accomplish it. I am storing my meta sprite frame data like this:
And I'm using a macro that gets called on a timer set for every half second:
My problem is that my array of metasprite frames is an array of 16 bit addresses. Because of that, indexing into it means that I have to increment my counter variable twice to get to the next slot. Because of that my animation data needs an increased frame count in order to work correctly. As I've defined it above, my walk animation won't work, I need to actually store the number of frames as $06 to make it work. How do people usually solve this type of problem?
Code:
player_walking_1:
.byte $00,$32,%00000000,$00
.byte $00,$33,%00000000,$08
.byte $08,$34,%00000000,$00
.byte $08,$35,%00000000,$08
player_walking_2:
.byte $00,$36,%00000000,$00
.byte $00,$37,%00000000,$08
.byte $08,$38,%00000000,$00
.byte $08,$39,%00000000,$08
etc...
player_walk_animation:
.byte $04 ; number of frames
.word player_walking_1, player_walking_2, player_walking_3, player_walking_4
.byte $00,$32,%00000000,$00
.byte $00,$33,%00000000,$08
.byte $08,$34,%00000000,$00
.byte $08,$35,%00000000,$08
player_walking_2:
.byte $00,$36,%00000000,$00
.byte $00,$37,%00000000,$08
.byte $08,$38,%00000000,$00
.byte $08,$39,%00000000,$08
etc...
player_walk_animation:
.byte $04 ; number of frames
.word player_walking_1, player_walking_2, player_walking_3, player_walking_4
And I'm using a macro that gets called on a timer set for every half second:
Code:
.macro play_animation animation, counter, sprite_ptr
; load sprite frame counter
ldx counter
; increase x to put offset at the begginning of frame data
inx
; set current sprite to current animation frame
lda animation, x
sta sprite_ptr + 0
inx
lda animation, x
sta sprite_ptr + 1
; get number of frames and store it in temp1
lda animation
sta temp1
; check if frame counter is equal to number of frames
ldx counter
cpx temp1
beq reset_counter
; advance frame counter if counter < number of frames
inx
inx
stx counter
jmp callback_done
reset_counter:
lda #$00
sta counter
callback_done:
.endmacro
; load sprite frame counter
ldx counter
; increase x to put offset at the begginning of frame data
inx
; set current sprite to current animation frame
lda animation, x
sta sprite_ptr + 0
inx
lda animation, x
sta sprite_ptr + 1
; get number of frames and store it in temp1
lda animation
sta temp1
; check if frame counter is equal to number of frames
ldx counter
cpx temp1
beq reset_counter
; advance frame counter if counter < number of frames
inx
inx
stx counter
jmp callback_done
reset_counter:
lda #$00
sta counter
callback_done:
.endmacro
My problem is that my array of metasprite frames is an array of 16 bit addresses. Because of that, indexing into it means that I have to increment my counter variable twice to get to the next slot. Because of that my animation data needs an increased frame count in order to work correctly. As I've defined it above, my walk animation won't work, I need to actually store the number of frames as $06 to make it work. How do people usually solve this type of problem?