如何根据分数更改 SKSpriteNode?

How do I make an SKSpriteNode change dependent on a score?

我正在尝试编写一个更酷的 Flappy Bird 版本,其中的鸟会根据分数变化为更酷的东西。非常感谢您的帮助。这是声明这只鸟的完整代码。我怎样才能制作一个根据分数更新小鸟的函数?

let birdTexture1 = SKTexture(imageNamed: "bird-01")
birdTexture1.filteringMode = .nearest
let birdTexture2 = SKTexture(imageNamed: "bird-02")
birdTexture2.filteringMode = .nearest

let anim = SKAction.animate(with: [birdTexture1, birdTexture2],     timePerFrame: 0.2)
let flap = SKAction.repeatForever(anim)

bird = SKSpriteNode(texture: birdTexture1)
bird.setScale(2.0)
bird.position = CGPoint(x: self.frame.size.width * 0.35, y:self.frame.size.height * 0.6)
bird.run(flap)

bird.physicsBody = SKPhysicsBody(circleOfRadius: bird.size.height / 2.0)
bird.physicsBody?.isDynamic = true
bird.physicsBody?.allowsRotation = false

bird.physicsBody?.categoryBitMask = birdCategory
bird.physicsBody?.collisionBitMask = worldCategory | pipeCategory
bird.physicsBody?.contactTestBitMask = worldCategory | pipeCategory

self.addChild(bird)

您可以在分数变量的 didSet 函数中创建此行为。

每当您增加(或减少)玩家的分数时,它就会运行。

var score: Int {
    didSet {
        if score > 69 {
            bird.removeAllActions()

            let coolBirdTexture1 = SKTexture(imageNamed: "coolbird-01")
            coolBirdTexture1.filteringMode = .nearest
            let coolBirdTexture2 = SKTexture(imageNamed: "coolbird-02")
            coolBirdTexture2.filteringMode = .nearest

            let anim = SKAction.animate(with: [coolBirdTexture1, coolBirdTexture2], timePerFrame: 0.2)
            let flap = SKAction.repeatForever(anim)

            bird.texture = coolBirdTexture1
            bird.run(flap)
        }
    }
}