Swift Sprite Kit SKAction的持续时间是否会减慢函数的执行?

Swift Sprite Kit SKAction的持续时间是否会减慢函数的执行?,swift,sprite-kit,sprite,updates,skaction,Swift,Sprite Kit,Sprite,Updates,Skaction,我在我的精灵套件游戏中有一个功能,其中游戏角色死亡并有一个死亡动画。在这个相同的方法中,我设置了一些属性,让我的更新函数知道游戏结束了,这样分数就可以停止增加和其他一些事情。但是当这运行时,deathAnimation函数似乎会减慢正在设置的其他变量的执行。例如,当分数应该停止时,分数会不断增加。为什么会这样?这与我的更新功能有关,还是持续时间较长的动画会使整个方法无法立即执行? 提前谢谢你的帮助 这是我的脱乙烷方法 func deathAnimation() { //set shiel

我在我的精灵套件游戏中有一个功能,其中游戏角色死亡并有一个死亡动画。在这个相同的方法中,我设置了一些属性,让我的更新函数知道游戏结束了,这样分数就可以停止增加和其他一些事情。但是当这运行时,deathAnimation函数似乎会减慢正在设置的其他变量的执行。例如,当分数应该停止时,分数会不断增加。为什么会这样?这与我的更新功能有关,还是持续时间较长的动画会使整个方法无法立即执行? 提前谢谢你的帮助

这是我的脱乙烷方法

func deathAnimation() {
    //set shield for death
    self.yourDead = true
    self.shield.position = CGPointMake(self.frame.maxX * 2, self.frame.maxY + self.ape.size.height * 10)
    self.shield.hidden = true
    self.shieldActivated = false
    //set Ape image to default
    self.ape.runAction(SKAction.setTexture(SKTexture(imageNamed: "Ape"), resize: true))
    self.ape.zRotation = 0
    //changes physicsBody values so He doesn't collide
    self.ape.physicsBody?.dynamic = false
    self.ape.physicsBody?.categoryBitMask = ColliderType.Asteroid.rawValue
    self.ape.physicsBody?.contactTestBitMask = ColliderType.Ape.rawValue
    self.ape.physicsBody?.collisionBitMask = ColliderType.Ape.rawValue
    self.ape.zPosition = 10     //bring the ape to the front
    let death = SKAction.sequence([
                        SKAction.group([
                                SKAction.scaleBy(4, duration: 0.5),
                                SKAction.moveTo(CGPointMake(self.frame.minX + ape.size.width * 2, self.frame.minY - ape.size.width * 2), duration: 2),
                                SKAction.repeatAction(SKAction.rotateByAngle(CGFloat(M_PI_4), duration: 0.2), count: 8)
                            ]),
                        SKAction.runBlock({self.moveToGameOverView();})
                    ])
    ape.runAction(death)        //run the animation sequence
}
这是我的代码,我在这里检查玩家是否死亡,这在更新函数中。我没有包括所有的更新函数,因为它可能比你想看的要多

//take Asteroids off the screen and increment score
    enumerateChildNodesWithName("asteroid", usingBlock: {(node: SKNode!, stop: UnsafeMutablePointer <ObjCBool>) -> Void in
        //move the asteroids off the screen
        node.position = CGPointMake(node.position.x, node.position.y + self.gravity)
        //if it is out of screen
        if node.position.y > self.frame.size.height + self.largeAsteroid.size.width {
            node.removeFromParent()
            if !self.yourDead {         //if your not dead
                self.score++
                self.scoreText.text = String(self.score)
                //increase Asteroid speed
                if self.score > 20 * self.tensCounter {
                    self.gravity++
                    self.tensCounter++
                }
            }
        }
    })
//将小行星从屏幕上移除并增加分数
enumerateChildNodesWithName(“小行星”,使用block:{(节点:SKNode!,停止:unsafemeutablepointer)->中的Void
//将小行星移出屏幕
node.position=CGPointMake(node.position.x,node.position.y+self.gravity)
//如果它不在屏幕上
如果node.position.y>self.frame.size.height+self.large.size.width{
node.removeFromParent()节点
如果!self.yourDead{//如果你没有死
自我评分++
self.scoreText.text=字符串(self.score)
//提高小行星速度
如果self.score>20*self.tenscore计数器{
自重++
自动张力计数器++
}
}
}
})

提供的代码看起来不错。不过,您可以尝试检查一些东西

  • 确保您没有反复调用
    deathAnimation()

  • 确保在
    deathAnimation()
    之前未使用name执行
    EnumerateChildNodes操作

  • 确保你没有在其他地方增加分数


  • 这些是我认为你的分数在你设置
    self.yourDead=true
    后会继续上升的唯一原因,希望这会有所帮助。

    我想看看你在哪里检查
    self.yourDead
    。另外,在运行scaleBy、moveTo和repeatAction的同时运行self.moveToGameOverView()的事实也是可疑的。我编辑了我的问题,以包括我在哪里使用“self.yourDead”。另外,“self.moveToGameOverView()”不是其他动作的组的一部分,因此它在动画之后运行,因此游戏在动画之后结束。是的,关于moveToGameOverView()你是对的,我在前面阅读时以为它是与这些动作分组的,但你是对的,它们是按顺序排列的。我看不出您发布的内容有任何问题,除非您在运行deathAnimation之前运行enumerateChildNodes。如果这是唯一一个递增分数的地方,那么分数应该停止。实际上……您是否在阻止每个循环调用deathAnimation()?这肯定会让事情变慢,但无法解释分数问题。是的,
    deathAnimation()
    只有在有联系人时才会被调用,这意味着游戏结束,如果它确实被调用了不止一次,那么SKAction.scaleBy(4,duration:0.5)
    会让精灵变得巨大,我想我会注意到这一点。不知道为什么这不能阻止分数增加。