Pipes!

Now the bird is flapping but there are no enemies, so the game is pretty boring. It's time to add some obstacles: pipes!

Implementing the pipes node

To implement the pipes as they were in the original game, we need two classes: PipesNode, which contains the top and bottom pipes, and Pipes, which creates and handles PipesNode.

Let's begin with Pipes and add it as an actor to GameScene:

//...
let pipes = Pipes(topPipeTexture: "topPipe.png", bottomPipeTexture: "bottomPipe").addTo(screenNode)

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

The Pipes class holds the texture name, and it is added to the node tree:

import SpriteKit class Pipes { private class var createActionKey : String { get {return "createActionKey"} } private var parentNode: SKSpriteNode! ...

Get Swift: Developing iOS Applications 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.