2015-05-11 50 views
0

我想在兩個圖像之間切換以暫停並玩我的遊戲。我嘗試使用下面的代碼,但它不起作用。我宣佈暫停並播放爲SKSpriteNodes()如何切換兩個圖像以暫停並在SWIFT中玩遊戲,SpriteKIT

任何人都可以幫忙嗎?

func paused(){ 
    self.scene?.view?.paused = true 
    pause.removeFromParent() 
} 

// PLAYING FUNCTION 
func playing(){ 
    self.scene?.view?.paused = false 
    play.removeFromParent()  
} 
+0

你不給足夠的信息。你從場景中刪除「暫停」和「播放」,但是你什麼時候將它們添加回來? –

回答

0

正如別人告訴你的,你沒有給我們足夠的信息給你一個確切的答案。

無論如何,我看到的代碼的一小部分對我來說似乎並不合適。

首先,您可能不應該使用兩個節點,也不要刪除它們中的任何一個。
如果你的目標只是改變圖標,你應該使用相同的節點,並簡單地改變它的texture屬性。

如果你想要一個例子,我可以給你一個例子。

編輯:這裏是例子

// In this example, we will call playPauseNode the SKSpriteNode you are using as a button 
var isPlaying = true 

func buttonTouched() { 
if isPlaying { // If the game is playing 
playPauseNode.texture = SKTexture(imageNamed: "theNameOfYourPlayButtonImage") 
isPlaying = false 
} 

else { // If the game is paused 
playPauseNode.texture = SKTexture(imageNamed: "theNameOfYourPauseButtonImage") 
isPlaying = true 
} 

} 

我相信它應該表現爲您預期的...

+0

請做,我真的需要幫助完成我的比賽。謝謝 – superkaskus

+0

我會回家的時候;) –