Re: How would I go about drawing the same object multiple times?
Posted: Sat Sep 09, 2017 7:20 pm
tried to make as simple as possible:
this is how i've been setting up my constructors (i guess is what you'd call it) using a class like structure. it works for me anyway.
Code: Select all
testCube = {}
function testCube:create(x,y)
local m = setmetatable({},{__index = testCube})
m.locationX = x
m.locationY = y
m.width = 55
m.height = 55
return m
end
function testCube:draw()
love.graphics.rectangle("fill",self.locationX,self.locationY,self.width,self.height)
end
function love.load()
allCubes = {}
end
function love.update(dt)
if love.mouse.isDown(1) then
c = testCube:create(love.mouse.getX(),love.mouse.getY())
table.insert(allCubes,c)
end
end
function love.draw()
for k,v in ipairs(allCubes) do
v:draw()
end
end