Game Development Reference
To access the Game Center leaderboards and achievements, you refer to them by ID.
To be able to query and update the correct leaderboards and achievements, you should
note the leaderboard category ID strings and the achievement ID strings.
I've set up one leaderboard with a score format of Elapsed Time and a leaderboard cat-
egory ID of Playtime . For achievements I've entered one achievement, with an
achievement ID of PlayedForTenSeconds , that grants the player five achieve-
Feel free to set up additional leaderboards and achievements, but keep in mind that the
example code in this chapter relies on at least one leaderboard with a category ID of
Playtime and one achievement with an achievement ID of PlayedForTenSe-
conds to exist.
AppController and NavigationController
Now it's time to create the actual Xcode project. You can start the project from any
cocos2d project template. The cocos2d 2.0 templates actually include rudimentary
Game Center functionality. You can also use an already existing project with no Game
Beginning with version 2.0, cocos2d removed the RootViewController class in
favor of a UINavigationController class. This class is created in the Ap-
pDelegate files, which declare the AppController class. Note that AppCon-
troller is simply the name for the app delegate class in cocos2d projects. You can
obtain a reference to the AppController from anywhere via the UIApplication
class' delegate property:
AppController* app = (AppController*)[UIApplication sharedApplication].delegate;
You can then access the navigation controller via the navController property:
[app.navController presentModalViewController:viewController animated:YES];
You may be wondering what you need the navigation controller for. Game Center
needs a view controller like the UINavigationController class to be able to
show its built-in UIKit user interface. The navController provided by cocos2d
makes Game Center integration a lot easier.