Game Closure devkit support for iOS Game Center (GameKit) and Google Play Game Services for Android
devkit install https://github.com/gameclosure/gamekit
.
// The import statement for GameKit
import GameKit;
// Need to register an auth handler somewhere in your app. Note that this is a
// handler, not a callback, and it may be called multiple times as
// connections/disconnects occur.
GameKit.registerAuthHandler(function (err, player) {
// `err` will be set when user declines to game center. You should not attempt
// to use any of the other methods.
//
// `player` will have playerID and displayName when the user is logger in.
});
// Try to log the user in if they are not authenticated
if (!GameKit.authenticated) {
// This is generally good to do on startup. If the player signs in, your auth
// handler will run and you can start using other GameKit APIs.
GameKit.showAuthDialog();
}
Check the file js/native.js for param/return types on the interfaces discussed here. Methods and properties are enumerated below.
Return a list of leaderboards configured for your application
Return a list of scores for a given leaderboard
Show the Game Center auth dialog if the user isn't authed already.
Open up the native game center user interface
Show a game center notification
NOTICE: This feature is only supported on iOS. There is no equivalent on Android using Game Services.
Submit a single score to a single leaderboard
Unlock an achievement (Android only, TODO: iOS + full Android support)
Set a function to be called when the user's auth status changes.
Whether the user is currently authenticated with game center
Important! Read the official docs about testing your game. It's only 3 paragraphs and quite helpful.
After adding game center entitlements, you can go to the iOS simulator or your iDevice's settings and set sandbox mode under Settings > Game Center. You need to be logged into game center and reinstall your app to enable it.
The instructions below are a high level summary of requirements for using the GameKit plugin. Details of setting up your app in Google Play and the app in Game Services are easily found online and are out of scope for this discussion.
- Set up your application on Google Play
- Set up game services
- Make sure to add release and debug client IDs to the game services app.
- Add ladders, achievements, etc.
- Put configuration into
manifest.json
. A sample of this config is below.
{
"addons": {
"gamekit": {
"android": {
"app_id": "1234567890",
"ladders": {
"distance": "CgjI6OjVlJ4UEAIQAg"
}
}
}
}
}
- iOS should probably have some sort of
ladders
map to match Android so that the application can always refer to ladders by the same ID regardless of platform. - Achievements
- Challenges
- Matchmaking
- Turnbased