0
我目前正在做一個非常基本的「龐」遊戲。我有應用程序正在運行,但我想添加一個遊戲畫面。一旦用戶或計算機達到5分,我想要顯示轉場場景。如何從我的SKScene創建Segue到另一個UIViewController?
這是我的分數更新功能:
func addScore(playerWhoWon: SKSpriteNode) {
ball.position = CGPoint(x: 0, y: 0)
ball.physicsBody?.velocity = CGVector(dx: 0, dy: 0)
if playerWhoWon == main {
score[0] += 1
if score[0] >= 5 {
// call a function that segues to endGame()
}
let when = DispatchTime.now() + 0.7
DispatchQueue.main.asyncAfter(deadline: when) {
self.ball.physicsBody?.applyImpulse(CGVector(dx: 15, dy: 15))
}
} else if playerWhoWon == enemy {
score[1] += 1
if score[1] >= 5 {
// call a function that segues to endGame()
}
let when = DispatchTime.now() + 0.7
DispatchQueue.main.asyncAfter(deadline: when) {
self.ball.physicsBody?.applyImpulse(CGVector(dx: -15, dy: -15))
}
}
topLbl.text = "\(score[1])"
btmLbl.text = "\(score[0])"
}
我希望能夠調用「殘局」的功能,這塞格斯到「你贏了」或「你輸」的UIViewController,根據結果的遊戲。任何幫助非常感謝,謝謝!
我宣佈視圖控制器,並創建了我的SKScene VC和我youWinVC之間的SEGUE。然後,我在我的youWin函數中發佈了segue命令,該函數顯示屏幕上的獲勝遊戲: func youWin(){ self.ball.physicsBody?.isDynamic = false viewController?.performSegue(withIdentifier:「youWinSegue」,sender: viewController) } //我試圖確定segue本身和youWin視圖控制器,但仍然無法工作。有什麼建議麼? –
你可以嘗試self.viewController?.performSegue(withIdentifier:「identifier」,sender:self.viewController)另外,確保你在你的代碼中調用了這個函數。 –
我將自我前綴添加到視圖控制器,但沒有效果。在我的if score> = 5語句中,我稱之爲youWin函數。它的工作原理是因爲物理調整線(在我之前評論的segue命令中)在遊戲結束時停止了球,它不會延續到新的VC。 –