Game center integration

Does anyone have any sample code I could look at for integrating a cocos2d-x iOS game with Apple’s Game Center?

I searched these forums and found an old thread but it wasn’t very helpful …

Hi,

it’s not well documented but please take a look at:

And (currently) you have to add @public infront of RootViewController *viewController in you AppController.h. It’s not pretty but it should work :wink:

Feel free to ask if anything is unclear!

Best regards,
Michael

Michael Contento wrote:

Hi,
>
it’s not well documented but please take a look at:
[ … ]

Thanks. This is exactly what I am looking for, I think.

Haven’t actually started reading Apple’s documentation for Game Center so this may be a stupid question, but don’t I need a way to login with a user’s credentials … How does that work?

Edit: oh, I see your login member function now…

hi… i am new to game center …could you post a small tutorial on how to integrate gamecenter in cocos2d-x using your class??? thanks for the code… :).

t works fine on ios6 but in ios7 I am having the following problems. As of now I am trying to integrate achievements only. so the problems are related to achievements as of now…

post achievement: I have 9 achievements in the game only the first one shows the banner. Other dont show banner.

The points are updated for the other achievements but actual achievements are not shown as finished in gamecenter.

The show achievements: show the achievement view opens but I am unable to close it. Also, the points are not updated in that view. But If I go to the gamecenter the points are there.

Clear achievement doest work.

As I said earlier the above problems are only there in ios 7 and in ios6 it all works perfectly. Kindly help.

Hey, Where is the method for dismissing the game center popup view controller? I am getting an error when i click on done in the leaderboard popUp. How do i fix it?
I added this code,

-(void) leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
    AppController* appController = (AppController*) [UIApplication sharedApplication].delegate;
    [appController->viewController dismissModalViewControllerAnimated:YES];
}

but then i get an error saying
‘-[RootViewController leaderboardViewControllerDidFinish:]: unrecognized selector sent to instance 0xcd71bd0’

Please Help

Hi and sorry for my late response!

Beside adding avalon::GameCenter and all required files [1], you need to patch a few files in the ios/ folder of your project. Just have a look at this patch and everything should be clear :slight_smile:

Best regards,
Michael

*[1]* avalon/GameCenter.h and avalon/platform/gamecenter/{GameCenter.mm,GameCenterIos.h,GameCenterIos.m}

Michael Contento wrote:

Hi and sorry for my late response!
>
Beside adding avalon::GameCenter and all required files [1], you need to patch a few files in the ios/ folder of your project. Just have a look at this patch and everything should be clear :slight_smile:
>
Best regards,
Michael
>
*[1]* avalon/GameCenter.h and avalon/platform/gamecenter/{GameCenter.mm,GameCenterIos.h,GameCenterIos.m}

Dude… really thanks for the code… now the show achievements window closes. But there are a few bugs, but looks like it is more of an ios 7 issue. Still code works intact on ios6. :slight_smile:

  1. I have 9 achievements in the game. Only the banner for the first one shows… the rest wont show. But if I go the gamecenter app the points update in the main screen but when i go into my game the points are not updated. So I disabled banner show and just use a notification [GKNotificationbanner showBannerWithTitle:"Title" message:“Message” completionHandler:nil];

  2. The scores are different in the gamecenter app and show achievement popup/view.

  3. Also tho the banner shows for the first achievement it doesnt get updated in the show achievemnt popup. :S

its is really messed up… i guess gc is somewhat broken in ios7…. not sure…

Michael Contento wrote:

Hi and sorry for my late response!
>
Beside adding avalon::GameCenter and all required files [1], you need to patch a few files in the ios/ folder of your project. Just have a look at this patch and everything should be clear :slight_smile:
>
Best regards,
Michael
>
*[1]* avalon/GameCenter.h and avalon/platform/gamecenter/{GameCenter.mm,GameCenterIos.h,GameCenterIos.m}

Thanks for the code examples man. Are we allowed to use this? Is it open-source?

Yes, the patch and everything from avalon is open source and free to use for everyone :slight_smile:

Awesome. Thanks very much man. You saved me a lot of trouble. :slight_smile:

Hey Michael,
Thanks for posting the code, it really helps. Just wondering why do you save the achievements to the device? I don’t see that feature being implemented on Android.

Btw i’m getting an error on saying that I can’t assign RootViewController to id<GKAchievementViewControllerDelegate:
gkController.achievementDelegate = appController->viewController;

How can I fix this problem? Typecasting?