Love2D等于触摸控制



我有此代码用于鼠标:

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

因此,只要按下鼠标按钮,这就会发射枪支。我有触摸的屏幕按钮,我可以用love.touchpressed捕获单个触摸,但这一次会发射枪支。

我想要它,以便播放器可以触摸屏幕按钮,并且只要将枪持续固定下来。

使用:

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

或定义功能is_emptyany

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

最新更新