swift - Sprite Kit SKAction 是否具有持续时间慢的功能执行?

标签 swift sprite-kit sprite updates skaction

我的 Sprite 套件游戏中有一个函数,其中游戏角色死亡并有一个死亡动画。在同样的方法中,我设置了一些属性让我的更新函数知道游戏已经结束,这样分数就可以停止增加和其他一些东西。但是当它运行时,deathAnimation 函数似乎减慢了正在设置的其他变量的执行速度。因此,例如,当它应该停止时,分数会不断增加。为什么是这样?这与我的更新功能有关,还是具有持续时间的动画会减慢整个方法的执行速度? 提前感谢您的帮助!

这是我的 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++
                }
            }
        }
    })

最佳答案

提供的代码看起来不错。但是,您可以尝试检查一些内容。

  1. 确保您没有一遍又一遍地调用 deathAnimation()

  2. 确保您没有在 deathAnimation() 之前执行您的 enumerateChildNodesWithName

  3. 确保您没有在其他地方增加分数。

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

关于swift - Sprite Kit SKAction 是否具有持续时间慢的功能执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30563307/

相关文章:

css - <ul> Sprite 问题

swift - 获取变量的 bool 类型错误

ios - 如何从左到右更改带有动画的 CALayer 的宽度?

ios - 为场景添加新 Action 是否会自动删除之前在 SpriteKit 中的 Action ?

swift - didBeginContact 重新调整所有 physicsBody (Swift)

ios - 如何制作功能正常的动画按钮?

javascript - 显示部分图像(图像条中的子图像)而不压缩它?

c++ - cocos2dx中如何将Sprite对象保存到文件中?

ios - Wowza 直播问题

swift - 标题没有显示,每次我连接源和委托(delegate)时,程序都会崩溃,当我不连接它们时,它不会打印任何内容