Skip to content

rickgbw/cordova-plugin-game-center

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Game Center Plugin for Apache Cordova

This plugin allows developers to utilise the iOS Game Center in their Cordova / PhoneGap app.

The code under active development and currently has support for auth, submitting a score and showing leaderboards using the native viewcontroller.

Before you start

Adding Game Center support requires more than simple coding changes. To create a Game Center-aware game, you need to understand these basics before you begin writing code. The full outline of all the Game Center concepts and impacts can be viewed here.

Install

cordova plugin add https://github.com/leecrossley/cordova-plugin-game-center.git

You do not need to reference any JavaScript, the Cordova plugin architecture will add a gamecenter object to your root automatically when you build. It will also automatically add the GameKit framework dependency.

Usage

Auth

You should do this as soon as your deviceready event has been fired. The plug handles the various auth scenarios for you.

gamecenter.auth(successCallback, failureCallback);

Submit Score

Ensure you have had a successful callback from gamecenter.auth() first before attempting to submit a score. You should also have set up your leaderboard(s) in iTunes connect and use the leaderboard identifier assigned there as the leaderboardId.

var data = {
    score: 10,
    leaderboardId: "board1"
};
gamecenter.submitScore(successCallback, failureCallback, data);

Show leaderboard

Launches the native Game Center leaderboard view controller for a given period and leaderboard.

var data = {
    period: "today",
    leaderboardId: "board1"
};
gamecenter.showLeaderboard(successCallback, failureCallback, data);

The period options are "today", "week" or "all".

Submit Achievement

var data = {
    percent: 100,
    achievementId: "achievement1"
};
gamecenter.submitScore(successCallback, failureCallback, data);

Show Achievements

gamecenter.showAchievements(successCallback, failureCallback);

Reset Achievements

gamecenter.resetAchievements(successCallback, failureCallback);

Platforms

Supports iOS 6 and iOS 7 (there are differences in the native implementation). The Game Center is Apple specific and not applicable to other platforms.

License

MIT License

About

Cordova / PhoneGap Game Center Plugin for Apache Cordova >= 3.0.0

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 89.3%
  • JavaScript 10.7%