问题描述
我想从我的 GameScene 移动到 ViewController,当我触摸一个图像时,当我触摸一个 UIButton 时返回到 GameScene.它从 ViewController 到 GameScene 都有效,因为它是 UIButton.
I want to move from my GameScene to ViewController, when I touch an Image and back to GameScene when I touch an UIButton.It worked from ViewController to GameScene, because it is 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)
}
但是当我触摸 GameScene 上的图像时,我不知道要编写什么代码才能返回 ViewController.
But I don't know what code to write to go back to ViewController, when I touch that image, which is on GameScene.
我应该向 GameScene 写什么?
What should I write to GameScene?
谢谢
推荐答案
我认为这不是您应该做的...您应该使用 SKScene - 而不是 UIViewController - 进行导航/菜单.
I don't think this is what you're expected to do... You should be using an SKScene - instead of a UIViewController - for your navigation/menu.
但是,一篇帖子我发现确实解释了这一点(尽管它在 Obj-C):
But, one post I found did explain this (albeit it's in 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 版本应该看起来像这样(我不是专家,但语法还不错)...
The Swift version should look something like this (I'm no expert, but the syntax isn't too bad)...
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)
就其他答案而言:
- 这可能是我在这个主题上看到的最好的帖子:从 SKScene 展示 UIViewController
- 此外,我在场景之间转换时发现了这个:SpriteKit 如何创建和过渡到不同的场景(Swift 语言)
希望有帮助.我也有同样的问题,老实说,我好像一直都做错了!
I hope that helps. I had the same question, and to be honest, it looks like I was just doing it wrong the whole time!
这篇关于在 GameScene 和 ViewController Swift 之间移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!