我可以让 SKSpriteNode 在过渡期间出现在不同的场景中吗

Can I have SKSpriteNodes show up on a different scene during a transition

我正在制作游戏并且正在处理自定义过渡。当您单击 TitleScene 上的 playButton 时,它会移动 GameScene。这是它的动图。

现在我想让这些按钮落在 另一个场景之上,或者显示在另一个场景之上。所以基本上按钮需要在 GameScene 上,即使它们是 TitleScene 的一部分。这是我的转换代码:

let transition = SKTransition.revealWithDirection(SKTransitionDirection.Up, duration: 2)
transition.pausesIncomingScene = false
transition.pausesOutgoingScene = false

currentScene.view?.presentScene(futureScene, transition: transition)

我不确定该怎么做。需要任何帮助。

更新

我意识到这样做的唯一方法是将 SKSpriteNodes 从 TitleScene 复制到 GameScene。检查此代码:

func createTransition(transitionFrom presentScene: SKScene, to futureScene: SKScene, withTransition transition: transitionTypes) {

var yPositions : [CGFloat] = []
for child in presentScene.children as! [SKSpriteNode] {
    yPositions.append(child.position.y)
}
let topSprite = yPositions.maxElement() // finds the sprite closest to the top

for child in presentScene.children as! [SKSpriteNode] {
    if child.position.y == topSprite {
        var vel = CGFloat.random(-1, 1)
        if (vel < 0.3 && vel >= 0) {
            vel += 0.5
        }
        if (vel > -0.3 && vel <= 0) {
            vel -= 0.5
        }
        let fallAction = SKAction.applyTorque(vel, duration: 0.5) // slightly turns the Sprite

        presentScene.physicsWorld.gravity.dx = CGFloat.random(-0.3,0.3)

        child.physicsBody?.affectedByGravity = true // Become affected by gravity and falls

        child.runAction(fallAction, completion: {
            for otherChild in presentScene.children as! [SKSpriteNode] {

                if otherChild.name != "background" { //copies all Sprites except the background 

                    let copiedChild = otherChild.copy() as! SKSpriteNode
                    copiedChild.position.y += futureScene.frame.size.height

                    futureScene.physicsWorld.speed = presentScene.physicsWorld.speed
                    futureScene.physicsWorld.gravity = presentScene.physicsWorld.gravity //makes it so they have the same physicsWorlds

                    futureScene.addChild(copiedChild) 
                }
            }
        })

        let transition = SKTransition.pushWithDirection(SKTransitionDirection.Up, duration: 2)
        transition.pausesIncomingScene = false
        transition.pausesOutgoingScene = false

        presentScene.view?.presentScene(futureScene, transition: transition)
    }
}

}

这是它的样子:

你可以看到他们没有正确排列,有人知道我遗漏了什么吗?

您应该创建按钮的副本并将它们添加到 GameScene

设置按钮在 GameScene 上的初始位置等于按钮在 TitleScene 上的最后位置。

希望效果是你要的效果

场景一:一个大场景

+------------+   }
|            |   }
|   Title    |   }
|            |   }
|            |   }
|            |   }   Initially visible half of full scene.
| btn    btn |   }
|    Play    |   }
| btn    btn |   }
+------------+   }  }
|            |      }
|            |      }
|            |      }
|            |      }
|   game     |      }   Half of full scene visible after play button is pressed
|            |      }    (the game)
|            |      }
|            |      }
+------------+      }

当按下 Play 时,这个大矩形 (14x19) 会向上移动,这样顶部矩形就不再可见,而是底部矩形可见。因为这在技术上是一个大场景,所以 buttons/title 可以在两个 'scenes' 之间自由移动(它实际上只是一个大场景)。

场景 2:两个 'scenes' 重叠

             +------------+   }
             |            |   }
             |   Title    |   }
             |            |   }
             |            |   }
             |            |   }   Initially visible half of big scene.
             | btn    btn |   }     z-pos of the rectangle on the right is higher than
             |    Play    |   }      the z-pos of the one on the left, thereby allowing
             | btn    btn |   }     its contents to be visible above those of the gamescene.
+------------+            |   }  }
|            |            |      }
|            |            |      }
|            |            |      }
|            |            |      }
|   game     |            |      }   Half of scene and gamescene visible after play button 
|            |            |      }    is pressed (the game)
|            |            |      }
|            |            |      }
+------------+------------+      }

这些场景重叠,最右边场景的下半部分与最左边场景相匹配。当按下播放按钮时,两个场景以相同的速度向上移动,直到只有底部场景可见。实际上,最右侧场景的下半部分仍在较小场景的上方。

大场景的alpha0。对于大场景的上半部分,可以添加背景节点;此设置允许游戏可见并且按钮仍位于游戏上方。

为了确保不存在无法与游戏场景交互的问题,因为从技术上讲,它上面有一个场景(这可能会阻碍交互),请删除较大的场景或将其 z 位置更改为在游戏场景下方。这可能不是必需的,但以防万一……你知道的。

记住你不能真正嵌入场景(至少根据 this),所以你不能在场景 2 中真正使用两个场景。你也可以将游戏场景放在 SKNode 或类似的东西中这是一种解决方法。