animation help
Posted: Mon Sep 10, 2012 10:47 pm
Hi I have the following code
to make an animation, animations are within a png image
but it gives me error
Code: Select all
function love.load()
img = love.graphics.newImage("05.png")
coord = {x = 320, y = 20}
arriba = {
imgX = 0,
imgY = 144,
pasos = 0}
abajo = {
imgX = 0,
imgY = 0,
pasos = 0}
izquierda = {
imgX = 0,
imgY = 48,
pasos = 0}
derecha = {
imgX = 0,
imgY = 96,
pasos = 0}
dir = arriba
end
function love.update(dt)
mov()
pasos()
--bordes()
end
function love.draw()
love.graphics.draw(image, coord.x, coord.y, dir.imgX, dir.imgY)
end
function mov(dt)
if love.keyboard.isDown("up") then
dir = arriba
coord.y = coord.y - 1.5
dir.pasos = dir.pasos + 1.5
elseif love.keyboard.isDown("down") then
dir = abajo
coord.y = coord.y + 1.5
dir.pasos = dir.pasos + 1.5
elseif love.keyboard.isDown("left") then
dir = izquierda
coord.x = coord.x - 1.5
dir.pasos = dir.pasos + 1.5
elseif love.keyboard.isDown("right") then
dir = derecha
coord.x = coord.x + 1.5
dir.pasos = dir.pasos + 1.5
end
end
function pasos()
if dir.pasos >= 0 and dir.pasos < 10 then
dir.imgX = 0
end
if dir.pasos >= 10 and dir.pasos < 20 then
dir.imgX = 32
end
if dir.pasos >= 20 and dir.pasos < 30 then
dir.imgX = 64
end
if dir.pasos >= 30 and dir.pasos < 40 then
dir.imgX = 96
end
if dir.pasos > 40 then
dir.pasos = 0
end
end
but it gives me error