My code is as follows
Code: Select all
local anim8 = require 'anim8'
local spritesheet, animation
function love.load()
spritesheet = love.graphics.newImage('paulaa.png')
local g = anim8.newGrid(32, 48, spritesheet:getWidth(), spritesheet:getHeight())
animations = {
left = anim8.newAnimation(g(1,4, 2,4, 3,4, 4,4), 0.1, onLoop),
right = anim8.newAnimation(g(1,6, 2,6, 3,6, 4,6), 0.1, onLoop)
}
current_animation = animations.left
end
function love.update(dt)
if love.keyboard.isDown('a') then
current_animation = animations.left:update(dt)
end
end
function love.draw()
current_animation:draw(spritesheet, 100, 200)
end
When the current_animation is changed to animations.left and the key being pressed code is removed, the animation works perfectly.
I don't understand why my code is returning nil when 'a' is pressed and why the sprite is still from the start of the program.