title: one click animations with lua in LOVE
body: <p>I have recently been familiar with lua in LOVE 2D and watched some tutorials and now am trying to make a simple game. The game will feature a character who can run and when pressed 'space', attack(strike with his sword). When pressed 'space', it should go through all the frames/sprites of attacking animation. But the character is not going through all the frames and the interval between them seems really fast even though I kept it minimum.</p>
  
  <p>This is the code I am using to account for the key pressing.</p>
  
  <pre><code>self.animations = {
          ['idle'] = Animation{
              frames = {
                  self.frames[1]
              },
              interval = 1
          },
          ['attack'] = Animation{
              frames = {
                  self.frames[1], self.frames[2], self.frames[3], self.frames[4], self.frames[5], self.frames[6], self.frames[3]
              },
              interval = 0.25
          }
      }
  
      self.animation = self.animations['idle']
      self.currentFrame = self.animation:getCurrentFrame()
  
      self.behaviors = {
          ['idle'] = function(dt)
  
              if love.keyboard.wasPressed('space') then
                  self.dy = 0
                  self.state = 'attack'
                  self.animation = self.animations['attack']
              elseif love.keyboard.wasPressed('up') then
                  self.dy = -MOVE_DIST
              elseif love.keyboard.wasPressed('down') then
                  self.dy = MOVE_DIST
              else
                  self.dy = 0
              end
          end,
          ['attack'] = function(dt)
              self.animation = self.animations['attack']
              if love.keyboard.wasPressed('up') then
                  self.dy = -MOVE_DIST
              elseif love.keyboard.wasPressed('down') then
                  self.dy = MOVE_DIST
              else
                  self.dy = 0
                  self.state = 'idle'
                  self.animation = self.animations['idle']
              end
          end
  </code></pre>
  
  <p>This is my animation class that's responsible for transition effects</p>
  
  <pre><code>Animation = Class{}
  
  function Animation:init(params)
      --self.texture = params.texture
      self.frames = params.frames
      self.interval = params.interval or 0.05
      self.timer = 0
      self.currentFrame = 1
  
  
  end
  
  function Animation:getCurrentFrame()
      return self.frames[self.currentFrame]
  end
  
  function Animation:restart()
      self.timer = 0
      self.currentFrame = 1
  end
  
  function Animation:update(dt)
      self.timer = self.timer + dt
  
      if #self.frames == 1 then
          return self.currentFrame
  
      else
          while self.timer &gt; self.interval do
              self.timer = self.timer - self.interval
  
              self.currentFrame = (self.currentFrame + 1) % (#self.frames + 1)
  
              if self.currentFrame == 0 then
                  self.currentFrame = 1
              end
          end
      end
  end
  </code></pre>
  
  <p>Please help. I hope I asked the question correctly. Thanks in advance.</p>