Page 1 of 1

anim8 - How to change duration of running animation?

Posted: Fri Jan 29, 2016 2:05 am
by ismyhc
Hello,

New to love2d, and enjoying it. Im using aim8 which is working out really well. I have a question about durations.

I can't seem to change the duration of animation once its created. How would I do this? For instance, I want to slow the animation down when the user presses the down key.

Code: Select all

  -- setup animation frames
  player.left_anim_frames = {
      atlas.quads['player_left_01'],
      atlas.quads['player_left_02']
  }
  
  player.right_anim_frames = {
      atlas.quads['player_right_01'],
      atlas.quads['player_right_02']
  }
  
  player.center_anim_frames = {
      atlas.quads['player_center_01'],
      atlas.quads['player_center_02']
  }
  
  -- create animation
  player.animation = anim8.newAnimation(player.center_anim_frames, 0.25)
  player.animation['left'] = anim8.newAnimation(player.left_anim_frames, 0.25)
  player.animation['right'] = anim8.newAnimation(player.right_anim_frames, 0.25)
  player.animation['up'] = anim8.newAnimation(player.center_anim_frames, 0.1)
  player.animation['down'] = anim8.newAnimation(player.center_anim_frames, 0.5)
  
in the update function

Code: Select all


    if love.keyboard.isDown("down") then
      
      if self.animation.current ~= self.animation['down'] then
        self.animation.current = self.animation['down']
      end

    end

This code switches the animations correctly, but the duration is always the same as the first animation. Ive tried looking over the code, but I'm very new to lua. Obviously, hehe.

Thanks!

Re: anim8 - How to change duration of running animation?

Posted: Fri Jan 29, 2016 4:27 pm
by kikito
You can increase/decrease the duration by manipulating dt before passing it to `animation:update(dt)`.

For example, if you pass `animation:update(dt*0.5)` the animation will update at "half speed". If you pass `animation:update(dt*3)` it will go 3 times faster than usual. Put that number in a variable (`animation:update(dt*animSpeed)`) and you will be able to tune it up and down on the fly by changing that variable.

Re: anim8 - How to change duration of running animation?

Posted: Fri Jan 29, 2016 6:11 pm
by ismyhc
kikito wrote:You can increase/decrease the duration by manipulating dt before passing it to `animation:update(dt)`.

For example, if you pass `animation:update(dt*0.5)` the animation will update at "half speed". If you pass `animation:update(dt*3)` it will go 3 times faster than usual. Put that number in a variable (`animation:update(dt*animSpeed)`) and you will be able to tune it up and down on the fly by changing that variable.
Thanks for the quick reply! Worked like a charm!