Accessing a SpriteKit Scene’s View Controller

July 11th, 2016

Filed under: Game Development, iOS Development, Mac Development | Be the first to comment!

If you’re using Game Center in a SpriteKit game, you present Game Center view controllers to show things like leaderboards and achievements. To present a Game Center view controller, you need to access the SpriteKit scene’s view controller. The good news is accessing the scene’s view controller takes only one line of code. Adding the following line of Swift code in your SKScene subclass gives you access to the scene’s view controller:

let sceneViewController = self.view?.window?.rootViewController
Facebooktwittergoogle_plusredditmail

Tags:


Leave a Reply

Your email address will not be published. Required fields are marked *