我有一个关于love2d(lua )游标函数的问题。我不想让一个区域点击一个动作发生。
我开始跟踪x和y参数中的for循环。我想过的唯一其他问题是,它是否会经过一个数字/坐标的for循环,并在最后一个love.mouse.get()将结束的数字上完成,并允许光标在最后一个坐标上被单击(一个像素)。
for r = 660, 770 do --the x coordinates
mx = love.mouse.getX(r)
end
for f = 99.33, 169.66 do --the y coordinates
my = love.mouse.getY(f)
end以及如何组合这两个循环变量(r和f)。
总之,我希望能够点击一个区域并做一个动作。我知道没有love.load、love.update和love.draw函数,因为这只是一个测试文件,以了解这些函数是如何工作的。
谢谢您:)
发布于 2016-11-01 12:52:34
你想得太多了。您真正想要做的是在二维中定义最小值和最大值,侦听鼠标事件,然后检查鼠标位置是否在您的边界内。没有必要遍历整个范围。
考虑这个例子‘游戏’,我们画了一个简单的红色框,当点击它时,切换左上角的文本显示。
local box_dims = {
{ 660, 770 },
{ 99.33, 169.66 }
}
local show = false
function love.mousepressed (x, y)
if
x >= box_dims[1][1] and
x <= box_dims[1][2] and
y >= box_dims[2][1] and
y <= box_dims[2][2] then
show = not show
end
end
function love.draw ()
love.graphics.setColor(255, 0, 0, 255)
love.graphics.rectangle('fill',
box_dims[1][1], box_dims[2][1],
box_dims[1][2] - box_dims[1][1],
box_dims[2][2] - box_dims[2][1]
)
if show then
love.graphics.print('hello world', 10, 10)
end
end请查看文档,以确定哪个鼠标事件适合您。
https://stackoverflow.com/questions/40356519
复制相似问题