[anim8] attempt to call method draw (nil value) [SOLVED]
Posted: Sat Apr 27, 2019 9:07 pm
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:
Here are the relevant portions of my code:
I've also attached a .love file. I'm relatively new to programming and LÖVE in general, so any help would be appreciated.
Code: Select all
Error
main.lua:34: attempt to call method 'draw' (a nil value)
Traceback
main.lua:34: in function 'draw'
[C]: in function 'xpcall'
Code: Select all
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