Start an animation via lua at a specific frame.

  • #1, by SDMonoWednesday, 06. August 2014, 21:07 11 years ago
    Hi everyone.

    Well I try to start an animation executing a script at the start of my game. It works... so far so good.

    Here is the little script I have. smile

    
    local ani_volume = getObject("Animations[ani_volume]")
    
    if getVolume(eMusicVolume) == 100 then
    
    startAnimation(ani_volume)
    
    end
    
    


    BUT... I want the animation to start at a specific frame. I tried using setAnimFrames but somehow it does not work.

    Does anyone have an idea of how to specify the frame I want the animation to start from?

    Saludos,
    Gordon

    Forum Fan

    148 Posts


  • #2, by SimonSWednesday, 06. August 2014, 21:28 11 years ago
    Here you go:
    local ani = getObject("ActiveAnimations[ani_volume]")
    ani:setValue(VAnimationCurrentSpriteIndex, 10)
    

    The animation should be started before doing that. Alternatively you can use the first frame field:
    local ani = getObject("ActiveAnimations[ani_volume]")
    ani:setValue(VAnimationFirstFrame, 10)
    

    Thread Captain

    1593 Posts

  • #3, by SDMonoWednesday, 06. August 2014, 21:59 11 years ago
    Thank you SimonS!!!! grin Works Great!!!

    My final script looks like this:

    local ani_volume = getObject("Animations[ani_volume]")
    
    startAnimation(ani_volume)
    
    if getVolume(eMusicVolume) == 100 then
    
    local ani = getObject("ActiveAnimations[ani_volume]")
    ani:setValue(VAnimationFirstFrame, 21)
    ani:setValue(VAnimationLastFrame, 21)
    
    end
    



    Forum Fan

    148 Posts

  • #4, by afrlmeWednesday, 06. August 2014, 22:21 11 years ago
    Quick note: you don't have to store things in variables to use them. Sometimes it's better to store them in variables or tables if you need to access them multiple times for whatever reason.

    Additional note: Animations have to be active to manipulate them via lua script; well majority of the time.

    startAnimation("Animations[ani_volume]") -- can use full paths too
    
    if getVolume(eMusicVolume) == 100 then
     getObject("ActiveAnimations[ani_volume]"):setValue(VAnimationFirstFrame, 21)
    end
    

    ... if last frame already = 21 then there's no need to set it!

    Imperator

    7285 Posts

  • #5, by SDMonoThursday, 07. August 2014, 00:14 11 years ago
    Oh... I just wanted to loop that frame forever. For example if the eMusicVolume is at 95% it loops the frame 20 forever... and so on. I can even change the volume directly in the config.ini and when I go back into the game the sliders are at the right position.

    I did the whole thing so that my audio controls work in my options menu. I could not get my head around your slider setup and came up with that solution.

    I don't have sliders and you can move holding down the mouse. Just plus and minus buttons but that is fine with me.

    Forum Fan

    148 Posts

  • #6, by afrlmeThursday, 07. August 2014, 01:37 11 years ago
    The slider setup was not mine. I have written my own version, but have not yet shared it on the wiki. I've only shared the percentage display function part of it so far.

    But you are correct that you need to set both first & last frame if you want it to only play 1 specific frame.

    Imperator

    7285 Posts