作爲一般的堆棧溢出規則,你應該總是發佈一些你自己的代碼或你玩過的代碼。
我實際上也希望在遊戲中集成一個playOn按鈕。現在我還沒有找到完美的解決方案,但希望這有助於你走上正確的軌道。
第1步: 您是如何通過場景對遊戲進行編程的? 你只是暫停場景,你是否暫停節點,或者你是否從場景中移除所有的孩子?
我暫停我的場景的方式是創建一個worldNode,然後將需要暫停的所有對象添加到worldNode中。 你可以閱讀我的兩個回答問題的更詳細
Keeping the game paused after app become active?
Sprite moves two places after being paused and then unpaused
這樣在我暫停比賽,我其實不暫停這給了我更多的靈活性增加pauseMenus等。而且它似乎現場比暫停skView更順暢。
當玩家死亡時,我也會打電話暫停,這意味着如果我致電簡歷,我可以從他們離開的地方恢復敵人/障礙物。 所以我的遊戲結束的方法是這樣的
func gameOver() {
pause() // call pause method to pause worldNode etc
//show game over screen including playOn button
}
第2步: 現在關於重生的球員,這取決於他如何定位,有多遠如果你的球員大多是在他可以移動等 與您相同的區域可能只需按一下「PlayOn」就可以手動重新生成玩家,而不是像遊戲剛剛暫停時那樣恢復遊戲。
所以一旦你playOn按下按鈕,你可以在我的遊戲叫,像這樣
func playOnPressed() {
// Remove current player
// Doesnt have to be called, you could just change the position
player.removeFromParent()
// Add player manually again to scene or just reposition him
...
// Remove obstacle that killed player
// haven't found a great solution for this yet
// You could make the player not receive damage for 5 seconds to make sure you dont die immediately after playOn is pressed
// Call resume method, maybe with delay if needed
resume()
}
的方法如果您的播放位置,可能是所有在屏幕上,因爲,我已經與一些事情打轉轉至今。
我創建了一個位置屬性,以跟蹤玩家的位置
playerPosition = CGPoint!
,比我的場景更新方法,我不斷更新這個方法給玩家的 實際位置。
override func update(currentTime: CFTimeInterval) {
if gameOver = false {
playerPosition = player.position
}
}
我不是一直在與「playOnPressed」方法玩弄,
func playOnPressed() {
// Remove current player
//Doesnt have to be called, you could just change the positioon
player.removeFromParent()
// Add player manually again to scene or just reposition him
...
player = SKSpriteNode(...
player.position.x = playerPosition.x - 40 // adjust this so it doesnt spawn where he died but maybe a bit further back
player.position.y = playerPosition.y // adjust if needed
// Remove obstacle that killed player
// haven't found a great solution for this yet
// You could make the player not receive damage for 5 seconds to make sure you dont die immediately after playOn is pressed
// Call resume method, with delay if needed
resume()
}
我希望這有助於你和你的playOn按鈕玩耍,如果有人有更好的辦法,我也將不勝感激非常。