Skip to content

Simplest Cordova/Android plugin for submitting a score to a Google Play Services Leaderboard.

License

Notifications You must be signed in to change notification settings

thetypingpuppy/ezleaderboard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ezleaderboard

Installation

cordova plugin add https://github.com/thetypingpuppy/ezleaderboard.git --variable PLAY_APP_ID=123456789012

Add the paths to the ezleaderboard class. In your index.html (or any other relevant html files), add the following to the <head> tag area.

<script type="text/javascript" src="plugins/ezleaderboard/ezleaderboard.js"></script> 

Initialisation

First step is initialisation of the ezleaderboard class.

function onDeviceReady() {
    var ezl = new ezleaderboard();
}

Authorisation - iOS Only

For iOS Game Center needs authorising. Best do this in onDeviceReady.

function onDeviceReady() {
    if (/(ipod|iphone|ipad)/i.test(navigator.userAgent)){
        ezl.auth(successCallback(), errorCallback());
    }

    function successCallback(){
        console.log("iOS Game centre authorised.");
    }

    function errorCallback(){
        console.log("Game centre authorisation error.");
    }
}

Submit Score

The argument array is a single entry array composed of one object. The object must contain the key: score for both iOS and Android. Specifically for iOS the leaderboardID key needs to be given as well.

function addScore(){
    var args = [{score: 100, leaderboardID_ios: "ios_leaderboard_id", leaderboardID_droid: "droid_leaderboard_id"}];
    ezl.submitToLeaderboard(successCallback, errorCallback, args);
}

Show Leaderboard

On android the leaderboard in Game Play Services app will load automatically, in iOS it needs to be shown manually.

function addScore(){
    var args = [{score: 100, leaderboardID_ios: "ios_leaderboard_id", leaderboardID_droid: "droid_leaderboard_id"}];
    ezl.submitToLeaderboard(successCallback(), errorCallback(), args);

    function successCallback(){
        // If iOS show leaderboard
        if (/(ipod|iphone|ipad)/i.test(navigator.userAgent)){
            var args = [{leaderboardID_ios: "ios_leaderboard_id", showAchievements: "false"}];
            ezl.showLeaderboard(function(){console.log("iOS Game centre leaderboard loaded.")}, function(){"Game centre leaderboard failed to load."}, args);
        }
    }

    function errorCallback(){
        console.log("Game centre score submission error.");
    }
}

About

Simplest Cordova/Android plugin for submitting a score to a Google Play Services Leaderboard.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published