Drawing many things at once using a loop
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 1
- Joined: Mon Jul 13, 2015 10:07 am
Drawing many things at once using a loop
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.
Re: Drawing many things at once using a loop
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.
Yes, please upload an example .love-file. That way we can have a look at it and give specific advice, rather than guessing.
Check out my blog on gamedev
Re: Drawing many things at once using a loop
If I understood what you want then this might help
I'm using a table of coordinate pairs for the squares.
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
Who is online
Users browsing this forum: No registered users and 3 guests