在GameScene和ViewController Swift之间移动
我想从我的GameScene移动到ViewController,当我触摸一个图像,并返回到GameScene,当我触摸一个UIButton。 它从ViewController工作到GameScene,因为它是UIButton。
我已经这样做了:
@IBAction func playbut(sender: UIButton) { var scene = GameScene(size: CGSize()) let skView = self.view as! SKView! skView.ignoresSiblingOrder = true scene.scaleMode = .ResizeFill scene.size = skView.bounds.size skView.presentScene(scene) }
但是我不知道什么代码要写回到ViewController,当我触摸那个在GameScene上的图像的时候。
我应该写什么GameScene?
谢谢
我不认为这是你所期待的…你应该使用SKScene而不是UIViewController来做你的导航/菜单。
但是,我发现的一个post解释了这个(尽pipe它在Obj-C中):
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil]; UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"PurchasedVC"]; //Call on the RootViewController to present the New View Controller [self.view.window.rootViewController presentViewController:vc animated:YES completion:nil];
Swift版应该看起来像这样(我不是专家,但语法不错)…
var mainStoryboard = UIStoryboard(name: "Main_iPhone", bundle: nil) var vc = mainStoryboard.instantiateViewControllerWithIdentifier("PurchasedVC") as! UIViewController self.view.window?.rootViewController?.presentViewController(vc, animated: true, completion: nil)
在其他答案方面:
- 这可能是我见过的最好的post: 从SKScene演示UIViewController
- 另外,我发现这个在场景之间转换: SpriteKit如何创build和转换到不同的场景(Swift语言)
我希望有帮助。 我有同样的问题,说实话,看起来我只是一直做错了!