从另一个SKScene中呈现一个SKScene [英] Presenting an SKScene from within another SKScene
问题描述
在我的主UIViewController中,我定义了两个SKScenes.我只想先显示gameScene
,然后再显示uiScene
,这是由gameScene
中的操作(按暂停按钮)触发的.
Inside my main UIViewController, I'm defining two SKScenes. I want to present only gameScene
at first, and then present uiScene
later, triggered by an action in gameScene
(hitting the pause button).
问题在于,包含两个场景的视图skView
在UIViewController之外无法识别.
The problem is that skView
, the view containing both scenes, is not recognized outside of the UIViewController.
代码在下面.任何帮助将不胜感激.
The code is below. Any help would be appreciated.
class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let skView = view as SKView
let gameScene = GameScene(size: view.bounds.size)
gameScene.scaleMode = .ResizeFill
skView.presentScene(gameScene)
let uiScene = UIScene(size: view.bounds.size)
uiScene.scaleMode = .ResizeFill
uiScene.backgroundColor = UIColor.clearColor()
//skView.presentScene(uiScene) // I want to present this line from within gameScene.
}
}
推荐答案
let reveal = SKTransition.flipHorizontalWithDuration(0.5)
let scene = uiScene(size: size)
self.view?.presentScene(scene, transition:reveal)
您可以在一个场景中从一个场景过渡到另一个场景.我的代码来自 http://www.raywenderlich.com/84434/上一节中的sprite-kit-swift-tutorial-beginners .
You can transition from one scene to another from within the scene. My code is pulled from http://www.raywenderlich.com/84434/sprite-kit-swift-tutorial-beginners in the last section.
记住要在要从其转换的场景中导入要转换到的场景的标题.
Remember to import the header of the scene you are transitioning TO in the scene you are transitioning FROM.
这篇关于从另一个SKScene中呈现一个SKScene的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!