2017-03-21 37 views
3

シーンの一時停止と一時停止の2つの問題があります。一時停止する一時停止/一時停止後に一時停止したシーン(停止していない状態)でSKActionを実行しないようにするには、一時停止/一時停止後にノードのテクスチャは変更されません。

playPause = SKSpriteNode(imageNamed: "buttPause.png") 
    playPause.name = "pause" 
    playPause.setScale (0.65) 
    playPause.position = CGPoint(x: -self.frame.width/2.55 , y: self.frame.height/2.27) 
    playPause.zPosition = 10 

    self.addChild(playPause) 

私が設定した機能やボタンの一時停止を解除シーン+チェンジテクスチャ:今とき、私

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 
    for touch in touches { 
     location = touch.location(in: self) 
     node = self.atPoint(location) 
     if node.name == "pause" { 

      buttonpauseplayTouched() 



     } 
     else {print ("Blank space")} 
    } 

} 

を:私はボタンのタッチを設定している

func buttonpauseplayTouched() { 

    if isPlaying { 
     playPause.texture = SKTexture(imageNamed: "buttPlay") 
     isPlaying = false 
     self.scene?.view?.isPaused = true 
    } 

    else { 
     playPause.texture = SKTexture(imageNamed: "buttPause") 
     isPlaying = true 
     self.scene?.view?.isPaused = false 
    } 

} 

私がボタンを持っていますタッチポーズボタン、私は一時停止することができますシーンのポーズ解除、しかしテクスチャは変更されません?なにが問題ですか?または、一時停止時に別のspritekitnodeをシーンに追加したい場合、私はできません。

第2の問題は、他のSKSpriteNodesが現れていることです。私がタッチするとアクションが設定されました。シーンが一時停止している間にタッチすると、何も起こりませんが、シーンをポーズ解除すると、オブジェクトの動作が実行されます。シーンが一時停止しているときに、オブジェクトに対してアクションを実行できないようにする方法を防止する方法。私は試してみます:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 
for touch in touches { 
    location = touch.location(in: self) 
    node = self.atPoint(location) 
    if node.name == "pause" { 

     buttonpauseplayTouched() 



    } 
    else if scene?.view?.isPaused == true && node.name == "object" {print ("Nothing!!")} 
    } 
    else {print ("Blank space")} 
} 

} 

成功しません。任意のヒントありがとう。

更新日:

もう一度おねがいします! レイヤーを使用したソリューションが優れています。試してみるとうまくいきます! 1つの小さな問題は、背景を動かすことです:

override func didMove(to view: SKView) { 
    createBackground() 
    } 
func createBackground(){ 
    for i in 0...3 { 
     background = SKSpriteNode(imageNamed: "background1.png") 
     background.name = "background" 
     background.setScale(0.694) 
     background.position = CGPoint(x: 0, y: CGFloat(i) * background.size.height) 
     background.zPosition = 1 


     gameLayer.addChild(background) 
    } 
} 
func moveBackground(){ 

    gameLayer.enumerateChildNodes(withName: "background", using: ({ 
     (node, error) in 

     node.position.y -= 7 

     if node.position.y < -((self.background.size.height)) { 
      node.position.y += (self.background.size.height) * 3 

     } 

    })) 

} 
override func update(_ currentTime: TimeInterval) { 
    moveBackground() 
} 

私はgameLayerを一時停止すると、まだ背景が動いています。 gameLayerが一時停止しているときに移動地点を停止するコードを編集するにはどうすればよいですか?私はコードの少しの変更だけがこれを解決することを願っています。ありがとう!

答えて

3

自分のコントロールを自分のレイヤー(SKNode)controlsLayer.addChild(pauseButton)と自分のレイヤー "gameLayer"のゲームオブジェクトに配置してから、ゲームを一時停止したいときは、gameLayerを一時停止します(gameLayer.isPaused =真実)。これは私が個人的にロンが言ったのファンですが、ちょうどお見せしたい、移動するゲームオブジェクトを停止し、一時停止されているの外観を与えるが、それでもアクションのようなものに私を可能にする、オブジェクトを追加するなど

override func update(_ currentTime: TimeInterval) { 

    if !gameLayer.isPaused { 
     moveBackground() 
    } 
} 
+0

ありがとうございます!レイヤーを使ったソリューションはまさに私が探しているものです。私は移動する背景に問題があるので、私は質問を更新しました。任意のヒントありがとう。 –

+0

私はバックグラウンドを一時停止する方法を示すために私の答えを編集しました –

+0

作品!ありがとう!! –

1

あなたは数行でこれを行うことができる方法:だから

func buttonpauseplayTouched() { 

    playPause.texture = SKTexture(imageNamed: isPaused ? "buttonPlay" : "buttonPause") 
    //pausing the scene rather than a view 
    self.isPaused = !self.isPaused 
} 

、基本的には、シーンのisPausedプロパティに基づいて、あなたはテクスチャを選択します。その後、シーンの一時停止したプロパティを切り替えます。この場合、isPlaying変数は必要ありません。

+0

ありがとう!私は両方のソリューションを試して、うまく動作します!あなたが言ったように、レイヤーを持つソリューションはより良いです。私は移動するバックグラウンドのために私の質問を更新します。どのチップのおかげで。 –

関連する問題