First: This is should have been posted in the Support and Development section, next time you have an issue with your code post there instead (The General sections is more about off topic stuff or issues with LÖVE itself... etc)
Code: Select all
local Quad = love.graphics.newQuad
function love.load()
character = {}
character.player = love.graphics.newImage("sprite.png")
character.x = 50
character.y = 50
direction = "right"
iteration = 1
max = 8
idle = true
timer = 0.1
quads = {}
quads['right'] = {}
quads['left'] = {}
for j=1, 8 do
quads['right'][j] = Quad((j-1)*32, 0, 32, 32, 256, 32);
quads['left'][j] = Quad((j-1)*32, 0, 32, 32, 256, 32);
--Quad flip is now done in love.graphics.draw (with the scale value)
end
end
function love.update(dt)
if idle == false then
timer = timer + dt
if timer > 0.2 then
timer = 0.1
iteration = iteration + 1
if love.keyboard.isDown('right') then
sprite.x = sprite.x + 5
end
if love.keyboard.isDown('left') then
sprite.x = sprite.x - 5;
end
if iteration > max then
iteration = 1
end
end
end
end
function love.keypressed(key)
if quads[key] then
direction = key
idle = false
end
end
function love.keyreleased(key)
if quads[key] and direction == key then
idle =true
iteration = 1
direction = "right"
end
end
function love.draw()
--love.graphics.drawq is now part of love.graphics.draw
--since quads cant be flipped I use a negative scale in the X axis (sx) to flip the quad
--(direction == "right" and 1 or -1) means: if direction == "right" then 1 else -1 end, but returns that value
love.graphics.draw(sprite.player, quads[direction][iteration],
sprite.x, sprite.y, 0,(direction == "right" and 1 or -1), 1)
end
Here you have your issues solved to work with 0.9.2, check it out and try to learn what I did from them
PS: With this you could even use a single quads table because the direction only changes the scale value, so instead of using quads[direction][iteration] you could use quads[iteration], just remember to change the loop where you create the quads to this:
Code: Select all
quads = {}
-- quads['right'] = {} --Not needed anymore
-- quads['left'] = {} --Not needed anymore
for j=1, 8 do
quads[j] = Quad((j-1)*32, 0, 32, 32, 256, 32);
-- quads.right[j] = Quad((j-1)*32, 0, 32, 32, 256, 32); --Not needed anymore
-- quads.left[j] = Quad((j-1)*32, 0, 32, 32, 256, 32); --Not needed anymore
--Quad flip is now done in love.graphics.draw (with the scale value)
end