Cordova Game plugin
Overview
Show leaderboard and achievements (google play game and game center, SDK)
[android, ios] [cordova cli] [xdk] [phonegap build service]
Requires google play developer account https://play.google.com/apps/publish/
Requires apple developer account https://developer.apple.com/devcenter/ios/index.action
This is open source cordova plugin.
You can see Cordova Plugins in one page: http://cranberrygame.github.io?referrer=github
cf) Leaderboard game: Best score game Limited life ex) 1, 3 Limited time ex) 30 seconds Time is score Achievement Score ex) Achievement1 (Score 10)
Change log
1.0.109 Fixed crash issue when show leaderbord after logout. 1.0.112 Added show leaderboards method. 1.0.113 Fixed crash issue when submit score after logout. 1.0.115 Refixed crash issue when submit score after logout.
Install plugin
Cordova cli
https://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The Command-Line Interface - npm install -g cordova@6.0.0
//caution: replace 1064334934918 with your google play game app id cordova plugin add cordova-plugin-game --variable APP_ID="1064334934918"
Xdk
//caution: replace 1064334934918 with your google play game app id
https://github.com/cranberrygame/cordova-plugin-game/blob/master/doc/intelxdk.config.additions.xml
Cocoon
https://cocoon.io - Create project - [specific project] - Setting - Plugins - Custom - Git Url: https://github.com/cranberrygame/cordova-plugin-game.git - INSTALL - Save
//caution: replace 1064334934918 with your google play game app id
https://cocoon.io - Create project - [specific project] - Setting - Plugins - Installed - Git Url https://github.com/cranberrygame/cordova-plugin-game.git - ADD PARAMETER - Name: APP_ID Value: 1064334934918 - Save
Phonegap build service (config.xml)
https://build.phonegap.com/ - Apps - [specific project] - Update code - Zip file including config.xml
//caution: replace 1064334934918 with your google play game app id <gap:plugin name="cordova-plugin-game" source="npm" > <param name="APP_ID" value="1064334934918" /></gap:plugin>
Construct2
Download construct2 plugin: http://www.paywithapost.de/pay?id=4ef3f2be-26e8-4a04-b826-6680db13a8c8
Now all the native plugins are installed automatically: https://plus.google.com/102658703990850475314/posts/XS5jjEApJYV
Server setting
android (Google Play Game)
If you migrate android app from one build system to another build system (e.g from xdk to cocoon), link Android step ~ again.
//add game google play developer console - Game services - Add a new game - Enter the name of your game: Test App, Category: Puzzle //get YOUR_GOOGLE_PLAY_GAME_APP_ID google play developer console - Game services - [specific app] - get
ios (Game Center)
itunesconnect - 나의 App - [specific app] - Game Center - Enable for Single Game //leaderboard itunesconnect - 나의 App - [specific app] - Game Center - Add Leaderboard -단일 순위표 - 순위표 세트 식별 정보: testapp_leaderboard - 순위표 ID: testapp_leaderboard -점수 형식 유형: Integer -점수 제출 유형: 가장 높은 점수정렬 순서: 높은 점수순 -Add Language -언어: English -이름: Leaderboard -점수 형식: Integer (100,000,122) -Save //achievement1 itunesconnect - 나의 App - [specific app] - Game Center - 목표 달성 추가 -목표 달성 식별 정보: testapp_achievement1목표 달성 ID: testapp_achievement1점수 값: 20 (max 100)숨김: No여러 번 달성 가능: No언어 추가 - 언어: English 제목: Achievement1 (Score 10)사전 획득한 목표 달성 설명: Achievement1 (Score 10)획득한 목표 달성 설명: Achievement1 (Score 10)이미지: 512x512 png //achievement2 itunesconnect - 나의 App - [specific app] - Game Center - 목표 달성 추가 -목표 달성 식별 정보: testapp_achievement2목표 달성 ID: testapp_achievement2점수 값: 40 (max 100)숨김: No여러 번 달성 가능: No언어 추가 - 언어: English 제목: Achievement2 (Score 30)사전 획득한 목표 달성 설명: Achievement2 (Score 30)획득한 목표 달성 설명: Achievement2 (Score 30)이미지: 512x512 png //achievement3 itunesconnect - 나의 App - [specific app] - Game Center - 목표 달성 추가 -목표 달성 식별 정보: testapp_achievement3목표 달성 ID: testapp_achievement3점수 값: 60 (max 100)숨김: No여러 번 달성 가능: No언어 추가 - 언어: English 제목: Achievement3 (Score 60)사전 획득한 목표 달성 설명: Achievement3 (Score 60)획득한 목표 달성 설명: Achievement3 (Score 60)이미지: 512x512 png //achievement4 itunesconnect - 나의 App - [specific app] - Game Center - 목표 달성 추가 -목표 달성 식별 정보: testapp_achievement4목표 달성 ID: testapp_achievement4점수 값: 80 (max 100)숨김: No여러 번 달성 가능: No언어 추가 - 언어: English 제목: Achievement4 (Score 100)사전 획득한 목표 달성 설명: Achievement4 (Score 100)획득한 목표 달성 설명: Achievement4 (Score 100)이미지: 512x512 png //achievement5 itunesconnect - 나의 App - [specific app] - Game Center - 목표 달성 추가 -목표 달성 식별 정보: testapp_achievement5목표 달성 ID: testapp_achievement5점수 값: 100 (leave blank, max 100)숨김: No여러 번 달성 가능: No언어 추가 - 언어: English 제목: Achievement5 (Score 150)사전 획득한 목표 달성 설명: Achievement5 (Score 150)획득한 목표 달성 설명: Achievement5 (Score 150)이미지: 512x512 png can test before publish
API
//var leaderboardId = "REPLACE_THIS_WITH_YOUR_LEADERBOARD_ID";var achievementId1 = "REPLACE_THIS_WITH_YOUR_ACHIEVEMENT_ID1";var achievementId2 = "REPLACE_THIS_WITH_YOUR_ACHIEVEMENT_ID2";var achievementId3 = "REPLACE_THIS_WITH_YOUR_ACHIEVEMENT_ID3";var achievementId4 = "REPLACE_THIS_WITH_YOUR_ACHIEVEMENT_ID4";var achievementId5 = "REPLACE_THIS_WITH_YOUR_ACHIEVEMENT_ID5";/*var leaderboardId;var achievementId1;var achievementId2;var achievementId3;var achievementId4;var achievementId5;//androidif (navigator.userAgent.match(/Android/i)) { leaderboardId = "REPLACE_THIS_WITH_YOUR_LEADERBOARD_ID"; achievementId1 = "REPLACE_THIS_WITH_YOUR_ACHIEVEMENT_ID1"; achievementId2 = "REPLACE_THIS_WITH_YOUR_ACHIEVEMENT_ID2"; achievementId3 = "REPLACE_THIS_WITH_YOUR_ACHIEVEMENT_ID3"; achievementId4 = "REPLACE_THIS_WITH_YOUR_ACHIEVEMENT_ID4"; achievementId5 = "REPLACE_THIS_WITH_YOUR_ACHIEVEMENT_ID5";}//ioselse if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)) { leaderboardId = "REPLACE_THIS_WITH_YOUR_LEADERBOARD_ID"; achievementId1 = "REPLACE_THIS_WITH_YOUR_ACHIEVEMENT_ID1"; achievementId2 = "REPLACE_THIS_WITH_YOUR_ACHIEVEMENT_ID2"; achievementId3 = "REPLACE_THIS_WITH_YOUR_ACHIEVEMENT_ID3"; achievementId4 = "REPLACE_THIS_WITH_YOUR_ACHIEVEMENT_ID4"; achievementId5 = "REPLACE_THIS_WITH_YOUR_ACHIEVEMENT_ID5";}*/ //document; //windowgame;windowgame;; //windowgame;//leaderboardId, scorewindowgame;windowgame;windowgame; //windowgame;windowgame;windowgame;windowgame;windowgame;windowgame; //achievementId, incrementalStepOrCurrentPercent: Incremental step (android) or current percent (ios) for incremental achievement.windowgame;windowgame;windowgame;windowgame;windowgame;windowgame;//only supported on ios //windowgame;
Examples
example/index.html
example_tag/index.html
Test
android (Google Play Game)
//publish as alpha test (recommend) or beta test instead of production. google play developer console - [specific app] - APK - Alpha test - Upload as alpha test - Drag and drop apk and publish now as alpha test. //add test user for game google play developer console - Game services - [specific game] - test - add
Clear the default account so that a different account can be signed in without having to clear app data:1.androidSetting - Account - Google - Logout with previous google account and login with other google account2.iosSetting - Game Center - Logout with previous ios account and login with other ios account
ios (Game Center)
//itunes connect sand box (Caution!) itunes connect - User and role - Sand box test - add
the requested operation has been canceled or disabled by the userReenabling GameCenter after user-cancelled 3
Useful links
Cordova Plugins
http://cranberrygame.github.io?referrer=github