【问题标题】:How to end the touchesBegan function in swift spritekit如何在swift spritekit中结束touchesBegan函数
【发布时间】:2016-01-25 16:57:28
【问题描述】:

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

【问题讨论】:

    标签: xcode swift touchesbegan


    【解决方案1】:

    我认为没有办法默认将其关闭。

    只需创建一个布尔值

    var touchesAllowed = true
    

    比在你的 didBeginContact 方法中你将它设置为 false

    touchesAllowed = false
    

    并在您希望再次允许触摸时将其设置为 true

    touchesAllowed = true
    

    最后在你的 touches 方法一开始你检查它

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

    【讨论】:

    • 我知道它必须如此简单!感谢崩溃覆盖。 :)
    • 我的荣幸,快乐的编码
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多