Drawing many things at once using a loop

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.
Post Reply
moonkaman227
Prole
Posts: 1
Joined: Mon Jul 13, 2015 10:07 am

Drawing many things at once using a loop

Post by moonkaman227 »

Hi, I'm new both to lua and also to love. So i have a quick question, i did a little searching before making this post but I couldn't find exactly my problem probably because its simple. Any ways i have set up a loop that generates a x and a y coordinate and using the love.graphics.draw function draws a 1 by 1 square at that coordinate, The problem is that the square doesn't stay drawn instead it updates positions and just moves i want the program to draw the square then move on to the next one and draw that and so on until it creates a large square made up of tiny ones. If anybody could help me with this i would appreciate it. Also I will be happy to clarify/provide examples, Thank you.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Drawing many things at once using a loop

Post by micha »

Hi and welcome to the forum.

Yes, please upload an example .love-file. That way we can have a look at it and give specific advice, rather than guessing.
User avatar
rok
Prole
Posts: 36
Joined: Wed Dec 24, 2014 9:12 am
Location: Slovenia

Re: Drawing many things at once using a loop

Post by rok »

If I understood what you want then this might help :)

Code: Select all

function love.load()
  squares = {}
  love.graphics.setColor(255,255,255)
  newX, newY = 0, 0
end

function love.update(dt)
  if newY < 20 then
    newSquare = {}
    newSquare['x'] = newX
    newSquare['y'] = newY
    table.insert(squares, newSquare)
    if newX < 20 then
      newX = newX + 1
    else
      newX = 0
      newY = newY + 1
    end
  end
end

function love.draw()
  for i, v in ipairs(squares) do
    love.graphics.rectangle("fill",squares[i]['x'],squares[i]['y'],1,1)
  end
end
I'm using a table of coordinate pairs for the squares.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests