fredericdnd February 2016

Present SKScene from UIViewController - Swift

I would like to make a game using a UIViewController for the Menu and a SKScene for the GameScene.

When the player press the Play button on the Menu, I would like a transition between the Menu and the GameScene with something like :

let nextScene = GameViewController()
self.presentViewController(nextScene, animated: true, completion: nil)

But I got this error :

Could not cast value of type 'UIView' (0x19ff623e0) to 'SKView' (0x19f813e70).

How can I do this please ?

Answers


Clever Error February 2016

Your code inside of GameViewController is trying to treat self.view as a SKView but its actually a UIView.

You will either need to set the views class to SKView in the storyboard/xib or create it yourself in your view controllers loadView method.

Post Status

Asked in February 2016
Viewed 3,938 times
Voted 10
Answered 1 times

Search




Leave an answer