【发布时间】:2016-04-07 09:15:46
【问题描述】:
我问过一个与此类似的问题,但我问的是 Processing.JS。现在我正在用 LOVE2D Lua 制作一些东西,我想做的是我有一个按钮,当点击它时,它会在屏幕上添加一个圆圈。我已经有代码,当我单击并按住圆圈时,我可以移动它。但是当我添加第二个圆圈时,他们都使用相同的变量。我想要它,所以我编写了一次代码实例来移动和添加圆圈,但我可以多次调用它并且每个都是唯一的,而无需编写代码来预测无限数量的圆圈。这是我的代码:
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
但是当我右键单击添加一个圆圈(增加 for 循环运行的次数)时,它不会添加第二个圆圈让我独立于第一个圆圈移动。帮忙?
【问题讨论】: