Quad problem
Posted: Mon Aug 08, 2016 11:42 am
Hello all,
I was working on a platformer game with love2d,
and as a learning experience I decided to write my own
tools for it : (level editor + animation system) .
I use quads to only display a certain part of a sprite sheet.
But my code isn't working as expected
curanim never gets set to p.run in the update function.
Also p.sheet is my spritesheet
I was working on a platformer game with love2d,
and as a learning experience I decided to write my own
tools for it : (level editor + animation system) .
I use quads to only display a certain part of a sprite sheet.
But my code isn't working as expected
Code: Select all
function love.load()
p = {}
p.x = 50;
p.y = 50;
p.sheet = love.graphics.newImage("a.png")
p.speed = 50;
p.idle = love.graphics.newQuad(0,0,30,45,p.sheet:getDimensions())
p.run = love.graphics.newQuad(0,0,30,38,p.sheet:getDimensions())
p.curanim = p.idle
end
function love.update(dt)
if love.keyboard.isDown("right") then
p.x = p.x + (p.speed * dt)
p.curanim = p.run
end
if love.keyboard.isDown("left") then
p.x = p.x - (p.speed * dt)
end
if love.keyboard.isDown("down") then
p.y =p.y + (p.speed * dt)
end
if love.keyboard.isDown("up") then
p.y = p.y - (p.speed * dt)
end
end
function love.draw()
love.graphics.draw(p.sheet, p.curanim, p.x, p.y)
end
Also p.sheet is my spritesheet