如何在swift spritekit中结束touchesBegan函数

时间:2016-01-25 16:57:29

标签: xcode swift touchesbegan

我正在使用swift spriteKit构建游戏,我正在使用TouchesBegan函数和DidBeginContact函数,当调用DidBeginContact函数时,我希望TouchesBegan函数处于非活动状态。我搜索了有关如何实现这一目标的教程,但无济于事。一些帮助将是合法的。

1 个答案:

答案 0 :(得分:1)

我认为没有办法在默认情况下将其关闭。

只需创建一个bool

var touchesAllowed = true

在didBeginContact方法中,将其设置为false

touchesAllowed = false

并在需要再次触摸时将其设置为true

touchesAllowed = true

最后在你开始的触摸方法中检查它

guard touchesAllowed else { return }
/// rest of your touch code