Having trouble drawing each object in table
Posted: Sat Aug 27, 2016 2:38 am
Hey, I'm making a test project that draws ten objects in a table. The problem is that it only draws a single one of the blocks that I instantiate:
Here's the code:
Here's the code:
Code: Select all
texture = nil
-- Block class
Block = {pos, colorIndex}
function Block:new(x, y)
self.x = x
self.y = y
colorIndex = love.math.random(5)
return self
end
function Block:draw(self)
if(colorIndex == 1) then
love.graphics.setColor(170, 252, 74)
end
if(colorIndex == 2) then
love.graphics.setColor(232, 148, 12)
end
if(colorIndex == 3) then
love.graphics.setColor(255, 0, 100)
end
if(colorIndex == 4) then
love.graphics.setColor(12, 15, 232)
end
if(colorIndex == 5) then
love.graphics.setColor(13, 255, 148)
end
love.graphics.draw(texture, self.x, self.x)
love.graphics.setColor(255, 255, 255)
end
playerX = nil
playerY = nil
blocks = {1, 2}
function love.load()
texture = love.graphics.newImage("assets/Prototype.png")
for i=1,10 do
blocks[i] = Block:new(love.math.random(300), love.math.random(300))
end
playerX = 20
playerY = 10
end
function love.draw(dt)
love.graphics.draw(texture, playerX, playerY)
for i,k in ipairs(blocks) do
k:draw(k)
end
end
function love.update(dt)
end