2016-12-08 70 views
0

當我觸摸屏幕時,小鳥以正確的角度向上旋轉,但一旦觸摸結束就停留在那裏。嘗試在觸摸開始時旋轉小鳥,並且觸摸結束時向下旋轉(SceneKit)

我遊戲中的牆壁也停止了產卵!

這是我的代碼,如果任何人都可以看到我在做什麼錯誤,讓我知道:D。 會很感激。謝謝

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 


    if gameStarted == false{ 

     gameStarted = true 

     bird.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]) 

     bird.physicsBody?.velocity = CGVector(dx: 0, dy: 0) 
     bird.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 35)) 

     let rotateUp = SKAction.rotate(byAngle: 0.2, duration: 0) 
     bird.run(rotateUp) 


    } 
    else{ 

     if died == true{ 

     } 
     else{ 
      bird.physicsBody?.velocity = CGVector(dx: 0, dy: 0) 
      bird.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 35)) 



     } 
    } 

    for touch in touches{ 

     let location = touch.location(in: self) 

     if died == true{ 

      if restartButton.contains(location){ 
       restartScene() 
      } 
     } 
    } 



override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { 


    if gameStarted == false{ 
     gameStarted = true 

     bird.physicsBody?.affectedByGravity = true 

     let rotateDown = SKAction.rotate(byAngle: -0.2, duration: 0) 
     bird.run(rotateDown) 

    } 
} 

回答

0

這裏沒有很多的信息,但從我看到的。當你開始觸摸時,你將gameStarted設置爲true。所以你的if語句觸發結束將不會觸發,因爲gameStarted是真的。

+0

我可以添加更多我的編碼,如果這可以幫助你?你認爲我應該接觸Ended聲明嗎? – niX

+0

如果有幫助,我添加了其餘的觸摸代碼! @Jaybit – niX

+0

我不得不添加我的旋轉動作,如果死了== true語句。感謝您指點我正確的方向! – niX