Need help with anim8
Posted: Tue Dec 10, 2013 2:03 am
I'm trying to play animation while the player is moving; however, I keep getting these error messages:
Am I doing something wrong? I have also attached a .love file for reference. Thanks in advance.
My code:
Code: Select all
local anim8 = require 'anim8'
local player
function love.load()
local walk = love.graphics.newImage("image/player/male_walkcycle.png")
local g = anim8.newGrid(64, 64, walk:getWidth(), walk:getHeight())
player = {
walk = walk,
x = 200,
y = 200,
speed = 50,
animations = {
up = anim8.newAnimation(g('loop',1,'2-9'), 1.0),
down = anim8.newAnimation(g('loop', '20-27',1), 1.0),
left = anim8.newAnimation(g('loop', '11-18',1), 1.0),
right = anim8.newAnimation(g('loop', '29-36',1), 1.0)
}
}
player.animation = player.animations.down
end
function love.update(dt)
player.animation:update(dt)
-- Right
if love.keyboard.isDown("d") then
player.x = player.x + player.speed * dt
player.animation = player.animations.right
end
-- Left
if love.keyboard.isDown("a") then
player.x = player.x - player.speed * dt
player.animation = player.animations.left
end
-- Up
if love.keyboard.isDown("w") then
player.y = player.y - player.speed * dt
player.animation = player.animations.up
end
-- Down
if love.keyboard.isDown("s") then
player.y = player.y + player.speed * dt
player.animation = player.animations.down
end
end
function love.draw()
animation:draw(player.walk, player.x, player.y)
end