0
\$\begingroup\$

I have integrated Game Center into my game and I want to make an achievement that is earned if the user holds the #1 spot on Game Center.

How do I access that information with code?

\$\endgroup\$
3
  • 1
    \$\begingroup\$ How are you able to implement something into your game and not know what forums are...developer.apple.com/game-center There should be a forum link there somewhere. \$\endgroup\$
    – Sidar
    Commented Nov 15, 2013 at 23:59
  • \$\begingroup\$ Thank you for the quick responses. @Sidar This is my first game, I am 13, and I have been using Cocos2d for my first game. Cocos2d has a great community and I have used their forums and its the only one I have needed to use. Now that I have explored and found out about the forums it will replace the Cocos2d forums. \$\endgroup\$
    – PoKoBros
    Commented Nov 16, 2013 at 2:34
  • \$\begingroup\$ @PoKoBros You don't replace the forum. Apple Game Center and Cocos2d are two different things. \$\endgroup\$
    – Sidar
    Commented Nov 16, 2013 at 12:42

1 Answer 1

1
\$\begingroup\$

You can do this with the GKLeaderboard API. As described in the documentation for recovering score data, you want to use the leaderboard object to represent a query to the Game Center service for leaderboard information, specifically setting the range to [1, 1] to return only the top score. This code would look something like this:

GKLeaderboard * request = [[GKLeaderboard alloc] init];
request.range = NSMakeRange(1, 1);
[request loadScoresWithCompletionHandler:^(NSArray * scores, NSError * error) { 
   // Handle the error or process the scores.
}]; 

The scores array contains GKScore objects, which have a player ID field you can use to compare against the current player's ID to determine if they are the player holding the top score or not.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .