TiGameKitEasyModule

OTHER License

Stars
8

GameKit Easy Module Titanium

This is a module that integrates Apple's Game Kit API. Currently Leaderboards and Achievements are supported. You don't need to create a way to save scores locally because this module do it for you, and when a internet connection is available, it sends to Game Center server automagically. ;-)

Remember: Logout your regular Game Center account to enable Sandbox mode.

Getting Started

View the Using Titanium Modules document for instructions on getting started with using this module in your application.

Download

Download the compiled release here or install from gitTio

Accessing the Ti.GameKit Module

To access this module from JavaScript, you would do the following:

var GameKit = require('com.obigola.gamekit');

Methods

void initGameCenter({ success: <successCallback>, error: <errorCallback> })

Checks if GameKit is available on the current device and connect to Game Center server. Devices must be running iOS 5.0 or later.

Accepts one object with two properties:

  • callback success: Use it if you want to do something after the player was authenticated. This property is optional.

  • callback error: Use it if you want to do something after the player cannot be authenticated. This property is optional.

void submitScore(string identifier, string score)

Saves a score for the current user to the specified LeaderBoard

Accepts two arguments:

  • string identifier: The identifier for the LeaderBoard, as set up in your iTunesConnect for this app.
  • string score: The score the user accomplished.

void showLeaderboard(string identifier)

Shows a particular LeaderBoard to the user.

Accepts a single argument:

  • string identifier: The identifier for the LeaderBoard, as set up in your iTunesConnect for this app. This argument is optional, if you not set, the module shows the last LeaderBoard called on submitScore()

void submitAchievement(string identifier, string percentageEarned)

Saves a score for the current user to the specified LeaderBoard

Accepts two arguments:

  • string identifier: The identifier you set up in your iTunes Connect account for this app.
  • string percentageEarned: A float from 0 to 100 describing how close the user is to completing the achievement. Once reported, achievements cannot be downgraded (so if a user completes 50% of an achievement, you cannot kick them back to only 10% completed).

void showAchievements()

Shows Game Center Achiviements view.

void resetAchievements()

Reset all users achievements from Game Center server.

string getPlayerInfo()

  • Player ID
  • Alias
  • Photo (Photo is just "Player ID"+".png", you'll need to use Titanium.Filesystem API to access the image. See example file.)

void getLeaderboardScore({ identifier: string, topOf: int, success: <successCallback>, error: <errorCallback> })

Accepts one object with four properties:

  • string identifier: Set which Leaderboard you want to get scores.

  • int topOf: Set users limit that you want to get from Leaderboard, like "Top 15". It's limited to 100. Default value is 25. This property is optional.

  • callback success(response): Use it to manage scores.

    • object response: { object localPlayer, array playersInfo, array scores}
  • callback error: Use it if you want to do something after the scores cannot be returned. This property is optional.

Usage

See example.

Author

@bguidolim

Special Thanks

Nihal Ahmed

Module History

View the change log for this module.