如何在SKScene中执行segue?

时间:2021-09-17 20:40:55

I have been trying to perform a segue from within a sprite kit SKScene layer. My application requires the user to touch an image on the scene that would push up a new UIViewController. But every time I try to perform from within the SKScene game layer, it gives me output with has no segue with identifier error. I do have a segue and have specified it with an identifier.

我一直在尝试从精灵工具包SKScene层中执行一个segue。我的应用程序要求用户触摸场景中的图像,这会推高新的UIViewController。但是每次我尝试在SKScene游戏层内执行时,它都会给我输出没有带标识符错误的segue。我有一个segue并用标识符指定它。

My simple question, how can one perfrom segue with a SKScene game layer running? Please help me out.

我的简单问题是,如何运行SKScene游戏层?请帮帮我。

2 个解决方案

#1


10  

Segues belong to view controllers, not SpriteKit scenes. If you want to perform a segue from within a SpriteKit node's event handling code, you'll need to look up the view controller that owns the view presenting the scene. For example, in a SKScene subclass' touchesBegan:withEvent: method:

Segues属于视图控制器,而不是SpriteKit场景。如果要从SpriteKit节点的事件处理代码中执行segue,则需要查找拥有呈现场景的视图的视图控制器。例如,在SKScene子类'touchesBegan:withEvent:方法中:

UIViewController *vc = self.view.window.rootViewController;
[vc performSegueWithIdentifier:@"id" sender:nil];

#2


4  

Swift version :

Swift版本:

self.view!.window!.rootViewController!.performSegueWithIdentifier("gameOverSegue", sender: self)

#1


10  

Segues belong to view controllers, not SpriteKit scenes. If you want to perform a segue from within a SpriteKit node's event handling code, you'll need to look up the view controller that owns the view presenting the scene. For example, in a SKScene subclass' touchesBegan:withEvent: method:

Segues属于视图控制器,而不是SpriteKit场景。如果要从SpriteKit节点的事件处理代码中执行segue,则需要查找拥有呈现场景的视图的视图控制器。例如,在SKScene子类'touchesBegan:withEvent:方法中:

UIViewController *vc = self.view.window.rootViewController;
[vc performSegueWithIdentifier:@"id" sender:nil];

#2


4  

Swift version :

Swift版本:

self.view!.window!.rootViewController!.performSegueWithIdentifier("gameOverSegue", sender: self)