Love2d触控控制中的isDown等效方法?

我有以下代码针对鼠标:

if love.mouse.isDown(1) then
   self.player:fire()
end

所以,只要按住鼠标按钮,它就会开火。我有屏幕按钮可用于触摸,我可以使用love.touchpressed捕获单个触摸,但这会一次性开火。

我希望玩家可以触摸屏幕按钮,只要按住按钮,枪就会不断开火。

点赞
用户3432369
用户3432369

使用:

if next(love.touch.getTouches()) ~= nil then
    self.player:fire()
end

或者定义函数 is_empty 或者 any:

function is_empty(t)
    return next(t) == nil
end

if not is_empty(love.touch.getTouches()) then
    self.player:fire()
end

function any(t)
    return next(t) ~= nil
end

if any(love.touch.getTouches()) then
    self.player:fire()
end
2018-02-26 07:20:07