繁体   English   中英

从UIViewController呈现GameScene

[英]Present GameScene from UIViewController

我想从我的ViewController使用GameViewController呈现GameScene 我试过了:

// let GameControllerA2 = GameViewController()

            // let transition = CATransition()
            // transition.duration = 0.5
            // transition.type = kCATransitionPush
            // transition.subtype = kCATransitionFromRight
            // view.window!.layer.add(transition, forKey: kCATransition)

            // self.present(GameControllerA2, animated: true, completion: nil)

            if let vc3 = self.storyboard?.instantiateViewController(withIdentifier: "A2ID") as? GameViewControllerA2 {
                let appDelegate = UIApplication.shared.delegate as! AppDelegate
                appDelegate.window?.rootViewController!.present(vc3, animated: true, completion: nil)

代码照片

但这一切都行不通。 就好像我只是将[Button]从Storyboard拖到GameViewController它不会崩溃,但我需要它以编程方式。 有关我的流程的任何问题? 问,我会回复。

首先,您需要将故事板标识符分配给要在当前控制器上显示的视图控制器。 您可以在身份检查器部分的故事板中执行此操作

让该标识符为“StoryboardIdentifierForNewClass”,类名为NewClassViewController。 然后,

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("StoryboardIdentifierForNewClass") as! NewClassViewController
self.presentViewController(vc, animated: true, completion: nil)

这个想法非常简单。

首先,您需要向视图控制器添加SKView

接下来,您将创建一个GameScene对象,并将其添加到SKView

view.presentScene(scene)

而已。 现在,你的ViewController里面有你的GameScene。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM