Im new to Love2D and to programming in general.
I tried doing a simple running animation to a character but instead of doing it I get a weird glitch animation...
I saw that glitch happens to a different animation depending on which image is loaded first.
here is the code (hope you won't laugh at it):
Code: Select all
local imageFileRun
local imageFile
local frames = {}
local activeFrame
local currentFrame = 1
local imageFileX, imageFileY
function love.load()
imageFileRun = love.graphics.newImage ("axe bandit run.png")
frames[1] = love.graphics.newQuad(0,0,80,80, imageFileRun:getDimensions())
frames[2] = love.graphics.newQuad(80,0,80,80, imageFileRun:getDimensions())
frames[3] = love.graphics.newQuad(160,0,80,80, imageFileRun:getDimensions())
frames[4] = love.graphics.newQuad(240,0,80,80, imageFileRun:getDimensions())
frames[5] = love.graphics.newQuad(320,0,80,80, imageFileRun:getDimensions())
frames[6] = love.graphics.newQuad(400,0,80,80, imageFileRun:getDimensions())
frames[7] = love.graphics.newQuad(480,0,80,80, imageFileRun:getDimensions())
frames[8] = love.graphics.newQuad(560,0,80,80, imageFileRun:getDimensions())
imageFile = love.graphics.newImage ("Axe Bandit.png")
frames[1] = love.graphics.newQuad(0,0,80,80, imageFile:getDimensions())
frames[2] = love.graphics.newQuad(80,0,80,80, imageFile:getDimensions())
frames[3] = love.graphics.newQuad(160,0,80,80, imageFile:getDimensions())
frames[4] = love.graphics.newQuad(240,0,80,80, imageFile:getDimensions())
frames[5] = love.graphics.newQuad(320,0,80,80, imageFile:getDimensions())
frames[6] = love.graphics.newQuad(400,0,80,80, imageFile:getDimensions())
imageFileX = love.graphics.getWidth()/2-160
imageFileY = love.graphics.getHeight()/2-160
activeFrame = frames[currentFrame]
end
function love.draw()
if(love.keyboard.isDown('d'))
then love.graphics.draw(imageFileRun,activeFrame,imageFileX,imageFileY,0,4,4)
imageFileX = imageFileX + 1
else love.graphics.draw(imageFile,activeFrame,imageFileX,imageFileY,0,4,4)
end
end
local elapsedTime = 0
function love.update(dt)
elapsedTime = elapsedTime + dt
if love.graphics.draw(imageFileRun,activeFrame,imageFileX,imageFileY,0,4,4) then
if (elapsedTime > 0.15) then
if(currentFrame < 8) then
currentFrame = currentFrame + 1
else
currentFrame = 1
end
activeFrame = frames[currentFrame]
elapsedTime = 0
end
else
if (elapsedTime > 0.15) then
if(currentFrame < 6) then
currentFrame = currentFrame + 1
else
currentFrame = 1
end
activeFrame = frames[currentFrame]
elapsedTime = 0
end
end
end