I am quite new to lua and I am experiencing some difficulties with it. I am writing an animation class that looks like this :
Code: Select all
Animation = {}
Animation.__index = Animation
-- nbf : number of frame
function Animation.create(filename, x, y, width, height, nbf)
local self = {}
setmetatable(self,Animation)
self.img = love.graphics.newImage(filename)
self.img:setFilter("nearest","nearest")
self.x = x
self.y = y
self.width = width
self.height = height
self.nbf = nbf
self.frame = 0
for i=0,nbf do
self.quad[i] = love.graphics.newQuad(x + width*i, y, width, height, self.img:getWidth(), self.img:getHeight())
end
return self
end
function Animation:update(dt)
local anim_speed = 10
self.frame = (self.frame + anim_speed*dt) % self.nbf
end
function Animation:draw(x,y)
love.graphics.drawq(self.img, self.quad[math.floor(self.frame)], x, y)
end
Code: Select all
\animation.lua:16: attempt to index field 'quad' (a nil value)
Code: Select all
for i=0,nbf do
self.quad[i] = love.graphics.newQuad(x + width*i, y, width, height, self.img:getWidth(), self.img:getHeight())
end
Thanks a lot !