Just thought I'd share my revised animation engine with everyone. This is a pretty basic version of it. It is only configured for a single entity right now, but is easily configurable.
Here is a link to the pastebin of it: http://pastebin.com/yKxcqJ4H
The idea is pretty simple. Every frame in your loop you jsr to p_anim. You use p_anim_state as the offset into the tables of p_anim_start_lo and p_anim_start_hi. Then you set bit 7 of p_anim_state so that it will no longer go through the initialization process. It jumps to load the bytes from the animation frame you set, returns, and decrements p_anim_count, which is how many frames that the animation will last. Since it is initialized already and bit 7 is set, it will skip the init and process what is in p_anim_addy. Once p_anim_count reaches zero, the code in p_anim_load (which I tend to keep its sections unrolled) will make sure to grab the name of the next frame and also how many frames it will last.
Currently, this has the offset for each sprite to add from your base sprites position during each frame so that they tie together. Doing it this way allows more flexibility with the sprites and how they're arranged, rather than just being together all the time. It also helps if you need to have some flipped sprites that might not line up properly if you just tied the sprites together into a constant block. But of course this is configurable, so you could get rid of those bytes in the frames if you wanted to and do the norm (where 'sprites' is the beginning of your player):
Anyway, like I said it can be configured in different ways. I haven't expanded it yet to include other objects to animate yet, but shouldn't be too difficult for anyone else to expand it if they need to.
Note that you can put some of the things in the load subroutine in a better order to loop them if you want, change the order of the frame data too, to make looping even more simple.
Anyone may use this how they wish if they like it, hence sharing it haha
Here is a link to the pastebin of it: http://pastebin.com/yKxcqJ4H
The idea is pretty simple. Every frame in your loop you jsr to p_anim. You use p_anim_state as the offset into the tables of p_anim_start_lo and p_anim_start_hi. Then you set bit 7 of p_anim_state so that it will no longer go through the initialization process. It jumps to load the bytes from the animation frame you set, returns, and decrements p_anim_count, which is how many frames that the animation will last. Since it is initialized already and bit 7 is set, it will skip the init and process what is in p_anim_addy. Once p_anim_count reaches zero, the code in p_anim_load (which I tend to keep its sections unrolled) will make sure to grab the name of the next frame and also how many frames it will last.
Currently, this has the offset for each sprite to add from your base sprites position during each frame so that they tie together. Doing it this way allows more flexibility with the sprites and how they're arranged, rather than just being together all the time. It also helps if you need to have some flipped sprites that might not line up properly if you just tied the sprites together into a constant block. But of course this is configurable, so you could get rid of those bytes in the frames if you wanted to and do the norm (where 'sprites' is the beginning of your player):
Code:
p_tie_sprites:
lda sprites+0
sta sprites+4
clc
adc #$10
sta sprites+8
sta sprites+12
lda sprites+3
sta sprites+11
clc
adc #$08
sta sprites+7
sta sprites+15
rts
lda sprites+0
sta sprites+4
clc
adc #$10
sta sprites+8
sta sprites+12
lda sprites+3
sta sprites+11
clc
adc #$08
sta sprites+7
sta sprites+15
rts
Anyway, like I said it can be configured in different ways. I haven't expanded it yet to include other objects to animate yet, but shouldn't be too difficult for anyone else to expand it if they need to.
Note that you can put some of the things in the load subroutine in a better order to loop them if you want, change the order of the frame data too, to make looping even more simple.
Anyone may use this how they wish if they like it, hence sharing it haha