シーンの一時停止と一時停止の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が一時停止しているときに移動地点を停止するコードを編集するにはどうすればよいですか?私はコードの少しの変更だけがこれを解決することを願っています。ありがとう!
ありがとうございます!レイヤーを使ったソリューションはまさに私が探しているものです。私は移動する背景に問題があるので、私は質問を更新しました。任意のヒントありがとう。 –
私はバックグラウンドを一時停止する方法を示すために私の答えを編集しました –
作品!ありがとう!! –