How to segue to View Controller from skview

223 views Asked by At

As simple as this question may seem, I just couldn't figure it out. To the overflow community, I am using sprite kit to create a simple game, However when you lose the game I want to programmatically segue back to another viewController (basically the home screen). from The game scene I do not get access to "performSegueWithIdentifier" I've seen a couple answers that relate to this topic however non of them are in swift ... Any solutions? links of related questions include : Link1 Thank You

2

There are 2 answers

3
Alex Chesters On

I think you are misunderstanding SKViews. SKViews are just like a normal UIViews, they take place within a normal ViewController. You will therefore need to segue from the ViewController which is presenting your SKView.

I have the same issue in a game I have created (Ninja-Shooter). In my game, whenever I want to segue back the home screen I pass a value to NSUserDefaults.standardUserDefaults(). Then in my ViewController I am constantly listening for any change in that value, if the value does change, then I perform a segue.

Hope this helps!

0
Chris Mazile On

I have discovered that using NSNotification Center Can in fact derive the results I was looking for. If any one in the future needs detailed code I will edit to provide that