Topic: isAnimationOver?(help)

I can't seem to understand how isAnimationOver() works. How do I get animations to play in succession? Here is the code:

function Animate(anim_object,anim_walk,anim_btn,anim_speed)--,anim_sound)
    if isKeyPressed(anim_btn) then
        idle = false
        walking = true
        changeAnimation(anim_object,anim_walk)
        setAnimationSpeed(anim_object,anim_speed)
        --playSound(anim_sound)
        
    
    elseif onKeyUp(anim_btn) then
        idle = true
        walking = false
        changeAnimation(anim_object,1)
        
        if isAnimationOver(anim_object) then
            changeAnimation(anim_object,2)
            setAnimationSpeed(anim_object,.3)
        end
        --stopSound(anim_sound)
    end
end

I want the character to play a certain animation when a key is released. And then, after it plays that animation, I want it to play another animation (I would think this animation continues to play).

However, in this code, the first animation plays and the next animation never plays, it just keeps playing the first animaton (animation 1).

Last edited by Tutorial Doctor (2013-10-23 19:15:53)

Re: isAnimationOver?(help)

Currently your animation 2 is only played 1 frame (just after animation 1 is over), then on the next scene update you loop back to animation 1 because onKeyUp condition is satisfied.

You could do something like :

if isAnimationOver(anim_object) then anim3=true end

and add:

elseif anim3 then
        changeAnimation(anim_object,2)
        setAnimationSpeed(anim_object,.3)
end

Last edited by com3D (2013-10-23 20:04:02)

Re: isAnimationOver?(help)

I wasn't able to get it to work, so I reformatted my code:

person = getObject("Person")

walk_animation = 0
transition_animation = 1
idle_animation = 2

function Walk()
    changeAnimation(obj,walk_animation)
end

function Transition()
    changeAnimation(obj,transition_animation)
end

function BeIdle()
    changeAnimation(obj,idle_animation)
end

function Animate(obj)
    if isKeyPressed(anim_btn) then
        Walk()
        setAnimationSpeed(obj,anim_speed)
    end
    
    if onKeyUp(anim_btn) then
        Transition()
        BeIdle()
    end
end

function onSceneUpdate()
    Animate(person)
end

So the conditions I want is that if a key is pressed I want to play the walk animation. If the key is released I want the character to play a transition animation and then an idle animation, and keep doing the idle animation until the key is pressed again.

How would I set the conditionals up in the Animate() function exactly?  I know I have to use isKeyPressed().

Last edited by Tutorial Doctor (2013-10-23 21:11:21)

Re: isAnimationOver?(help)

Here is another iteration I have to test:

walk_animation = 0
transition_animation = 1
idle_animation = 2
speed = .3
btn = "W"


function Walk()
    changeAnimation(obj,walk_animation)
end

function Transition()
    changeAnimation(obj,transition_animation)
end

function BeIdle()
    changeAnimation(obj,idle_animation)
end

function Animate(obj)
    if isKeyPressed(btn) then
        Walk()
        setAnimationSpeed(obj,speed)
        walking =true
    
    elseif onKeyUp(btn) then
        Transition()
        transitioning=true
    end
    
    if isAnimationOver(obj) then
        transitioning = false
    end
    
    if not transitioning then
        BeIdle()
    end
end

function onSceneUpdate()
    Animate(person)
end

Last edited by Tutorial Doctor (2013-10-23 21:31:08)

Re: isAnimationOver?(help)

Looking at the Animate function I got the animations to play in sequence but now when I press the key I get a freeze frame of the idle animation:

walk_animation = 0
transition_animation = 1
idle_animation = 2
speed = .3
btn = "W"

function Walk(obj)
    changeAnimation(obj,walk_animation)
end

function Transition(obj)
    changeAnimation(obj,transition_animation)
end

function BeIdle(obj)
    changeAnimation(obj,idle_animation)
end

function Animate(obj)
    if isKeyPressed(btn) then
        Walk(obj)
        setAnimationSpeed(obj,speed)
        walking =true
    end
    
    if onKeyUp(btn) then
        Transition(obj)
        transitioning=true
    end
    
    if isAnimationOver(obj) then
        transitioning = false
    
    elseif not transitioning then
        BeIdle(obj)
    end
end

Last edited by Tutorial Doctor (2013-10-23 21:44:34)

Re: isAnimationOver?(help)

This should do the trick :

walk_animation = 0
transition_animation = 1
idle_animation = 2
speed = .3
btn = "W"

function Walk(obj)
    changeAnimation(obj,walk_animation)
end

function Transition(obj)
    changeAnimation(obj,transition_animation)
    if isAnimationOver(obj) then
        transitioning = false
    end
end

function BeIdle(obj)
    changeAnimation(obj,idle_animation)
end

function Animate(obj)
    if isKeyPressed(btn) then
        Walk(obj)
        setAnimationSpeed(obj,speed)
        walking =true
        transitioning = true -- get ready for transition
    end
    
    if onKeyUp(btn) then
        if transitioning then Transition(obj)
        else BeIdle(obj) end
    end
end

Last edited by com3D (2013-10-24 06:12:14)

Re: isAnimationOver?(help)

ugh! I was sure that would work, but now it doesn't both animations again, just loops one. I will go to another project for now, maybe it will come to me. Thanks com3D.

Last edited by Tutorial Doctor (2013-10-25 00:14:22)

Re: isAnimationOver?(help)

Maybe the functions are not in the right place. Just to be sure:

- all the code above must be put outside of onSceneUpdate()
- inside onSceneUpdate() call the Animate(obj) function