如何在 swift spritekit 中结束 touchesBegan 函数
How to end the touchesBegan function in swift spritekit
我正在 swift spriteKit 中构建游戏,我正在使用 TouchesBegan 函数和 DidBeginContact 函数,当调用 DidBeginContact 函数时,我希望 TouchesBegan 函数处于非活动状态。我搜索了有关如何完成此操作的教程,但无济于事。有些帮助是合法的。
我认为没有办法默认关闭它。
只需创建一个布尔值
var touchesAllowed = true
比在 didBeginContact 方法中将其设置为 false
touchesAllowed = false
并在您希望再次允许触摸时将其设置为 true
touchesAllowed = true
最后在开始时的 touches 方法中检查它
guard touchesAllowed else { return }
/// rest of your touch code
我正在 swift spriteKit 中构建游戏,我正在使用 TouchesBegan 函数和 DidBeginContact 函数,当调用 DidBeginContact 函数时,我希望 TouchesBegan 函数处于非活动状态。我搜索了有关如何完成此操作的教程,但无济于事。有些帮助是合法的。
我认为没有办法默认关闭它。
只需创建一个布尔值
var touchesAllowed = true
比在 didBeginContact 方法中将其设置为 false
touchesAllowed = false
并在您希望再次允许触摸时将其设置为 true
touchesAllowed = true
最后在开始时的 touches 方法中检查它
guard touchesAllowed else { return }
/// rest of your touch code