wanksta11
wanksta11

Reputation: 59

spritekit gamecenter leaderboard - how to show leaderboard from scene?

How can I call my showLeader() function from GameViewController.swift in GameScene.swift ? this is my showLeader function

func showLeader() {
    var vc = self.view?.window?.rootViewController
    var gc = GKGameCenterViewController()
    gc.gameCenterDelegate = self
    vc?.presentViewController(gc, animated: true, completion: nil)
}

Upvotes: 2

Views: 241

Answers (1)

Wraithseeker
Wraithseeker

Reputation: 1904

You make use of NSNotificationCenter to present the viewController from an SKScene. Remember to add the observer and then post the notification. Don't forget to deinit the NSNotification when you no longer need it or your app will crash.

Upvotes: 1

Related Questions