I've been trying for the past few hours or so to animate a walking sprite using anim8, but after looking through several tutorials and forum posts and tweaking my code, I got this error:
local anim8 = require "anim8/anim8"
local player
function love.load()
local walk = love.graphics.newImage("turtle_walking.png")
local g = anim8.newGrid(32, 32, walk:getWidth(), walk:getHeight())
player = {
-- player attributes
animations = {
right = anim8.newAnimation(g('1-2',1), 1)
}
}
player.animation = player.animations.right
end
function love.update(dt)
player.animation:update(dt)
if next(love.touch.getTouches()) ~= nil then
player.x = player.x + (player.speed * dt)
player.animation = player.animations.right
end
if love.keyboard.isDown("d") then
player.x = player.x + (player.speed * dt)
player.animation = player.animations.right
end
end
function love.draw()
player.animations:draw(player.walk, player.x, player.y)
end
I've also attached a .love file. I'm relatively new to programming and LÖVE in general, so any help would be appreciated.
walk = love.graphics.newImage("turtle_walking.png")
If walk is local it cant be reached outside of love.load, only use local for variables that you wont need outside of their code block, still use local whenever you can is a good practice.