title: How to add levels to Flappybird like game?
body: <p>This might be bit confusing.</p>
  
  <p>This is my override function ATM, where my walls are spawning every 2 seconds. </p>
  
  <pre><code>override func touchesBegan(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {
  
  
      if gameStarted == false{
  
          gameStarted = true
  
          mexican.physicsBody?.affectedByGravity = true
  
  
          let spawn = SKAction.run({
              () in
  
              self.createWalls()
  
          })
          let delay = SKAction.wait(forDuration: 2.0)
          let spawnDelay = SKAction.sequence([delay, spawn])
          let spawnDelayForever = SKAction.repeatForever(spawnDelay)
          self.run(spawnDelayForever)
  
  
          let distance = CGFloat(self.frame.width + wallPair.frame.width)
          let movePipes = SKAction.moveBy(x: -distance - 50, y: 0, duration: TimeInterval( 0.01 * distance))
          let removePipes = SKAction.removeFromParent()
          moveAndRemove = SKAction.sequence([movePipes,removePipes])
  
          mexican.physicsBody?.velocity = CGVector(dx: 0, dy: 0)
          mexican.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 65))
  </code></pre>
  
  <p>I have found a tutorial where the wall spawn duration is made faster but I am unsure how to incorporate this into my code as they have used a new function. </p>
  
  <p>My walls are being spawned in the override function which makes it hard for me to call this when adding my if statement.</p>
  
  <pre><code>     func startNewLevel(){
  
             levelNumber += 1
  
             if self.actionForKey("spawningEnemies") != nil{
             self.removeActionForKey("spawningEnemies")
             }
  
             var levelDuration = timeInterval()
             switch levelNumber {
             case 1: levelDuration = 2.0
             case 2: levelDuration = 1.8
             case 3: levelDuration = 1.6
             default: levelDuration = 0.5
             print("Cannot find level into")
             }
  
             let spawn = SKAction.run(spawnEnemy)
             let waitToSpawn = SKAction.waitForDuration(levelDuration)
             let spawnSequence = SKAction.sequence([waitToSpawn, spawn])
             let spawnForever = SKAction.repeatActionForever(spawnSequence)
             self.runAction(spawnForever, withKey: "spawningEnemies")
  </code></pre>
  
  <p>This is where I would be calling the function startNewLevel() but my wall spawning is set up in override func touchedBegan.</p>
  
  <pre><code>func didBegin(_ contact: SKPhysicsContact) {
      let firstBody = contact.bodyA
      let secondBody = contact.bodyB
  
      if firstBody.categoryBitMask == physicsCategory.bird &amp;&amp; secondBody.categoryBitMask == physicsCategory.wall{
  
  
          score += 1
          scoreLabel.text = "\(score)"
          firstBody.node?.removeFromParent()
  
          if score == 10 || score == 15 || score == 20{
          startNewLevel()
  
          if score &gt; UserDefaults().integer(forKey: "HIGHSCORE") {
              saveHighScore()
  
  
          }
  
      }
      else if firstBody.categoryBitMask == physicsCategory.bird &amp;&amp; secondBody.categoryBitMask == physicsCategory.wall{
  
          score += 1
          scoreLabel.text = "\(score)"
          secondBody.node?.removeFromParent()
  
  
          if score &gt; UserDefaults().integer(forKey: "HIGHSCORE") {
              saveHighScore()
  
          }
  
      }
  </code></pre>
  
  <p>This is probably really confusing but if anyone gets me HOLA you will be my favourite person on the earth. </p>