have a problem whith tis code
error this
Code: Select all
Error: main.lua:113: attempt to index global 'quads' (a nil value)
stack traceback:
main.lua:113: in function 'draw'
[string "boot.lua"]:410: in function <[string "boot.lua"]:373>
[C]: in function 'xpcall'
Code: Select all
--animazione sprite
function love.load()
--carico immagine
character = love.graphics.newImage("sprite.png")
--love.graphics.newQuad( x, y, width, height, sw, sh )
love.graphics.newQuad(0, 0, 32, 32, 256, 32)--primo quad
love.graphics.newQuad(32, 0, 32, 32, 256, 32)--secondo quad
love.graphics.newQuad(64, 0, 32, 32, 256, 32)--terzo quad
love.graphics.newQuad(96, 0, 32, 32, 256, 32)--quarto quad
love.graphics.newQuad(128, 0, 32, 32, 256, 32)--quinto quad
love.graphics.newQuad(160, 0, 32, 32, 256, 32)--sesto quad
love.graphics.newQuad(192, 0, 32, 32, 256, 32)--settimo quad
love.graphics.newQuad(224, 0, 32, 32, 256, 32)--ottavo quad
--ciclo per i quad
for i = 1,8 do
love.graphics.newQuad( (i-1)*32, 0, 32, 32, 256, 32 )
end
local Quad = love.graphics.newQuad function love.load()
character = love.graphics.newImage("sprite.png")
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]:flip(true,false);
x = true
y = false
end
end
local Quad = love.graphics.newQuad function love.load()
character = {}
character.player = love.graphics.newImage("sprite.png")
character.x = 50
character.y = 50
direction = "right"
interation = 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)
x = true
y = false
end
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
character.x = character.x + 5
end
if love.keyboard.isDown('left') then
character.x = character.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(character.player, quads[direction][iteration], character.x, character.y)
end
i use 0.8.0 version program in linux xubuntu
thanks for your understanding