My simple animation engine

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
Roth
Posts: 399
Joined: Wed Aug 03, 2005 3:15 pm
Contact:

My simple animation engine

Post by Roth » Mon Sep 19, 2016 2:55 pm

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):

Code: Select all

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
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

User avatar
OmegaMax
Posts: 83
Joined: Wed Sep 21, 2016 8:55 am
Location: Calgary.Alberta,Canada

Re: My simple animation engine

Post by OmegaMax » Sun Sep 25, 2016 3:32 pm

Mine is quite simple also,thanks for sharing as it's always fun looking at other ways.


http://pastebin.com/Qpe4g4Vi
Last edited by OmegaMax on Mon Oct 03, 2016 9:38 am, edited 1 time in total.

Roth
Posts: 399
Joined: Wed Aug 03, 2005 3:15 pm
Contact:

Re: My simple animation engine

Post by Roth » Fri Sep 30, 2016 6:46 pm

OmegaMax wrote:Mine is quite simple also,thanks for sharing as it's always fun looking at other ways.


http://pastebin.com/snJxi7qb
Right on, I agree!

I like the way you put how many sprites there are in the lower and upper nybble of that first byte. Sometimes I find other code to be difficult to read, but yours seems fairly straight forward. Thanks for sharing as well!

Post Reply