Randomly Generated Images Not Drawing
Posted: Sat May 04, 2013 7:54 am
I am working on a project and I have came across a bug but I don't know how to fix it :/ Take a look:
My canvas is scaled 8x8 and what I am trying to happen is the image to load up randomly spread down the height of the screen, they travel upwards until off the screen to then change image and start from the bottom again. I have passed all the right functions into the callback functions but I still don't know whats wrong.
Please help me. Thanks in advance, Kyle.
Code: Select all
clouds = {}
clouds.__index = clouds
function clouds.init()
local cld = {}
setmetatable(cld, clouds)
cld.batch = {}
for i=1, 9 do
table.insert(cld.batch, {love.graphics.newImage("graphics/cloud"..math.random(3)..".png"), math.random(width - 32), (i - 1)*1.92})
end
cld.v = 1
return cld
end
function clouds:draw()
love.graphics.setColor(255,255,255,255)
for i=1, #self.batch do
love.graphics.draw(self.batch[i][1], self.batch[i][2], self.batch[i][3])
end
end
function clouds:update(dt)
for i=1, #self.batch do
self.batch[i][3] = self.batch[i][3] + self.v * 20
if self.batch[i][3] < -16 then
self.batch[i][3] = height
self.batch[i][2] = math.random(width - 32)
self.batch[i][1] = love.graphics.newImage("graphics/cloud"..math.random(3)..".png")
end
end
if self.v < 10 then
self.v = self.v + dt
end
end
Please help me. Thanks in advance, Kyle.