无法调用 Spritekit 的 update() 函数中的函数

Can't call a function in Spritekit's update() function

我正在用 Swift 和 Spritekit 编写一个小型 2d 游戏。 我有一个 gameOver() 函数,它使视图转到另一个场景(结束游戏),它在 touchesBegan() 函数中工作正常,但在满足条件时在 update() 函数中它只是冻结游戏,没有不去新现场,有什么问题? 我的猜测是 update() 函数只有 1 帧的时间来完成这项工作,它不能在那么短的时间内完成 gameOver() 函数,是吗?

代码如下:

override func update(currentTime: CFTimeInterval) {
    if hero.position.y <= 0 {
        gameOver()
    }}

您的更新方法可能重复调用了 gameOver 方法。您需要添加一个 BOOL 并在第一次调用时将其设置为 true,以便只调用一次。