How would I go about drawing the same object multiple times?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
jpott
Prole
Posts: 8
Joined: Fri May 05, 2017 7:36 pm

Re: How would I go about drawing the same object multiple times?

Post by jpott »

tried to make as simple as possible:

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
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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], ChocolateLoxtl, Google [Bot] and 79 guests