A flying bird

Now, it's time to implement our hero.

Adding the Bird node

First of all, we must add a new character to the GameScene class:

class GameScene: SKScene {
    private var bird: Bird!
    //...
    override func didMoveToView(view: SKView) {
        //...
        bird = Bird(textureNames: ["bird1.png", "bird2.png"]).addTo(screenNode)
        bird.position = CGPointMake(30.0, 400.0)

        actors = [sky, city, ground, bird]
        //...
    }
}

We can see that this new class behaves like the other, which we have already implemented:

import SpriteKit class Bird : Startable { private var node: SKSpriteNode! private let textureNames: [String] var position : CGPoint { set { node.position = newValue } get { return node.position } } init(textureNames: [String]) { self.textureNames = textureNames node ...

Get Swift 2 By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.