About the error:attempt to call method 'flip' (a nil value)
Posted: Mon Jun 22, 2015 1:33 am
Hi, I'm a new lover.I learn love by following a tutorial.Below is my code:
I run the program, but take a error.I don't know the error why.Anyone can help me?
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);
quads.left[j]:flip(true, false)
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(sprite.player, quads[direction][iteration],
sprite.x, sprite.y)
end