anim8 - How to change duration of running animation?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
ismyhc
Prole
Posts: 5
Joined: Tue Nov 20, 2012 4:01 am

anim8 - How to change duration of running animation?

Post 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!
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

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

Post 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.
When I write def I mean function.
ismyhc
Prole
Posts: 5
Joined: Tue Nov 20, 2012 4:01 am

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

Post 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!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 4 guests