Animation logic using anim8
Posted: Sat May 17, 2014 2:52 pm
I'm using anim8 to handle animations for a platformer. I'm finding myself at a roadblock with some animations and I'm not sure how to proceed.
The way my animations are set up currently is in a table like so:
...
and the current animation is set based on the players state like so:
My problem is that, for some animations, I want the animation to always start on the first frame, and I want it to finish the entire animation before allowing the player to change his state.
So for example, the attack animation is 7 frames long. When I press the attack key, I want to set the players state to attack, which will begin playing the attack animation. I want this animation to play one time the entire way through and stop at the end no matter when the player lets go of hte attack key. Meaning, if he taps the key the animation plays one time through, or if he holds the key down forever the animation still plays only one time through.
I know there's a "pauseAtEnd" function in anim8, but as soon as I lift my finger off the key my player.state reverts to idle, which changes the animation before it's finished playing.
I'm looking for a solution that will easily cover any additional animations I decide to add. Is there an article anywhere that explains handling this kind of animation? Or if it's just something simple I'm missing could someone here offer any advice? Thanks!
The way my animations are set up currently is in a table like so:
Code: Select all
player.animations['walk'] = anim8.newAnimation(grid('1-8',1), 0.1)
player.animations['idle'] = anim8.newAnimation(grid('1-8',2), 0.1)
player.animations['longidle'] = anim8.newAnimation(grid('1-8',3), 0.1)
player.animations['climb'] = anim8.newAnimation(grid('1-8',4), 0.1)
player.animations['jump'] = anim8.newAnimation(grid('1-8',5), 0.1)
player.animations['duck'] = anim8.newAnimation(grid('1-8',6), 0.1)
player.animations['attack'] = anim8.newAnimation(grid('1-7',7), 0.1)
player.animations.current = player.animations['idle']
and the current animation is set based on the players state like so:
Code: Select all
function player.setState(state)
if player.animations.current ~= player.animations[state] then
player.animations.current = player.animations[state]
end
player.state = state
end
So for example, the attack animation is 7 frames long. When I press the attack key, I want to set the players state to attack, which will begin playing the attack animation. I want this animation to play one time the entire way through and stop at the end no matter when the player lets go of hte attack key. Meaning, if he taps the key the animation plays one time through, or if he holds the key down forever the animation still plays only one time through.
I know there's a "pauseAtEnd" function in anim8, but as soon as I lift my finger off the key my player.state reverts to idle, which changes the animation before it's finished playing.
I'm looking for a solution that will easily cover any additional animations I decide to add. Is there an article anywhere that explains handling this kind of animation? Or if it's just something simple I'm missing could someone here offer any advice? Thanks!