Reputation: 137
I am trying to use the Easy-Game-Center by DaRkD0G from GitHub in my game (swift sprite kit). However, when calling the EasyGameCenter.Swift (using
EasyGameCenter.sharedInstance(self)
in my GameScene) I get an error saying "Cannot convert value of type 'GameScene' to expected argument type 'UIViewController'". For the past couple days, I have tried changing up the different class types in EasyGameCenter but always get answers. Does anyone have any suggestions?
Upvotes: 0
Views: 297
Reputation: 10839
I'm the creator of this project.
You can't use the Game Center of Apple without UIViewController !
The Framework Game Center need UIViewController for work, this is the official documentation of Game Center Apple.
And Easy Game Center need create with delegate UIViewController for work perfectly, without it is impossible to use Game Center
Example projet Game Center + Sprite Kit : http://www.raywenderlich.com/60980/game-center-tutorial-how-to-make-a-simple-multiplayer-game-with-sprite-kit-part-1
Create instance with UIViewController :
This is for create the instance of EasyGameCenter
override func viewDidLoad() {
super.viewDidLoad()
EasyGameCenter.sharedInstance(self)
}
Add this, if you change UIViewController for notifies the view controller delegate was changed, it's optional if you not change UIViewController you do not need this method
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
EasyGameCenter.delegate = self
}
just like that, now you can import the project with CocoaPods
pod 'EasyGameCenter', :git => 'https://github.com/DaRkD0G/Easy-Game-Center-Swift.git'
Upvotes: 2
Reputation: 13665
Never used that library, but as message says :
"Cannot convert value of type 'GameScene' to expected argument type 'UIViewController'"
This is the method you are calling:
class func sharedInstance(delegate:UIViewController)-> EasyGameCenter {
if Static.instance == nil {
dispatch_once(&Static.onceToken) {
Static.instance = EasyGameCenter()
Static.delegate = delegate
Static.instance!.loginPlayerToGameCenter()
}
}
return Static.instance!
}
You have to pass an UIViewController as an argument instead of GameScene.
Upvotes: 1