2016-01-15 37 views
0

我接近開發遊戲的末尾,長話短說,當一個對象崩潰成爲其中一個障礙時,遊戲將結束。我已經得到了這部分,遊戲本身運行得非常好,但是我還有一步想要添加。'播放'功能是應用程序內購買? SpriteKit/Swift

我想在應用程序內添加一個'play on'功能,即從用戶遊戲最初結束的地方開始,以便繼續。我對整體上的應用內購買感到滿意,但我想我想知道的是,在應用程序購買之後,人們如何才能「玩」?我只是尋找一些基本的東西,我可以建立。

我是一個Stack新手,因爲我今天只創建了一個帳戶(但我已經編程了一段時間,這個網站已經幫了我很多次了),所以我很抱歉,如果有是在其他地方製作的重複線程。在決定發佈之前,我確實環顧了一個小時左右(而谷歌沒有幫助)。

回答

0

作爲一般的堆棧溢出規則,你應該總是發佈一些你自己的代碼或你玩過的代碼。

我實際上也希望在遊戲中集成一個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按鈕玩耍,如果有人有更好的辦法,我也將不勝感激非常。

相關問題