Game Development Reference
In-Depth Information
the playerID , the date the score was posted, and its rank , value , and format-
tedValue , which you should use to display the score to the user.
Fortunately for you, Apple provides a default leaderboard user interface. Instead of us-
ing the scores I just retrieved, I'll ignore them and use the onScoresReceived del-
egate method to bring up the built-in leaderboard view:
-(void) onScoresReceived:(NSArray*)scores
{
GameKitHelper* gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper showLeaderboard];
}
Game Kit has a GKLeaderboardViewController class, used to display the
Game Center leaderboard user interface, as shown in Listing 14-11 .
Listing 14-11 . Showing the Leaderboard User Interface
-(void) showLeaderboard
{
if (isGameCenterAvailable == NO)
return;
GKLeaderboardViewController* leaderboardVC = ←
[[GKLeaderboardViewController alloc] init];
if (leaderboardVC != nil)
{
leaderboardVC.leaderboardDelegate = self;
[self presentViewController:leaderboardVC];
}
}
The leaderboardDelegate is set to self , which means the GameKitHelper
class must implement the GKLeaderboardViewControllerDelegate pro-
tocol. The GameKitHelper class already implements this protocol:
@interface GameKitHelper : NSObject < GKLeaderboardViewControllerDelegate, ←
GKAchievementViewControllerDelegate>
 
 
Search Nedrilad ::




Custom Search