I have asked a question similar to this, but i was asking it for Processing.JS. Now i am making something out of LOVE2D Lua, what I'm trying to do is that i have a button where when clicked it adds a circle on-screen. I already have code that when i click and hold on the circle, i can move it around. But when i add a second circle, they both are using he same variables. I want it so i write once instance of the code to move and add the circle, but i can call it multiple times and each one be unique without writing code to anticipate an infinite amount of circles. Here is my code:
obn = 0
ellipsex = 50
ellipsey = 50
ellipsew = 50
ellipseh = 50
ellipser = 255
ellipseg = 0
ellipseb = 0
function love.draw()
mousex, mousey = love.mouse.getPosition()
for i=0,obn,1 do
ellipse()
end
end
function love.mousereleased(x, y, button)
if button == 2 then
obn = obn + 1
end
end
function love.update(dt)
if love.mouse.isDown(1) then
if mousex > ellipsex and mousex < ellipsex + ellipsew and mousey > ellipsey and mousey < ellipsey + ellipseh then
ellipsex = mousex
ellipsey = mousey
end
end
end
function ellipse()
love.graphics.setColor(ellipser, ellipseg, ellipseb)
love.graphics.ellipse("fill", ellipsex, ellipsey, ellipsew, ellipseh)
end
But when i right-click to add a circle(increment how many times the for-loop runs) it doesnt add a second circle for me to move independent from the first one. Help?