GameCenter API documentation

Functions for interacting with Apple Game Center. Supported on iOS.

Usage

To use this library in your Defold project, add the following URL to your game.project dependencies:

https://github.com/Dragosha/extension-gamecenter/archive/master.zip

Source code

The source code is available on GitHub

API reference

Modules

gamecenter

Game Center - tiny but funny extension. [icon:ios]

Enums

gamecenter.LEADERBOARD_TIME_SCOPE_TODAY

Constant.

gamecenter.LEADERBOARD_TIME_SCOPE_WEEK

Constant.

gamecenter.LEADERBOARD_TIME_SCOPE_ALLTIME

Constant.

gamecenter.LEADERBOARD_PLAYER_SCOPE_GLOBAL

Constant.

gamecenter.LEADERBOARD_PLAYER_SCOPE_FRIENDS_ONLY

Constant.


Functions

gamecenter.login() Request for log in.
gamecenter.reportScore() Report score to a specifed Leaderboard
gamecenter.showLeaderboards() Show a specified Leaderboard
gamecenter.showAchievements() Show achievements
gamecenter.submitAchievement() Submit Achievement

gamecenter.login(callback)

Parameter Type Description
callback function

Log in callback function.

Parameter Type Description
self object

The current object.

data table

A table containing alias and playerID

error table

A table containing eventual error information.

Request for log in.

Examples

local login_cb_complete = false

local function login_cb(self, data, error)
  if login_cb_complete then return end
  if(error) then
      print(error.error)
  elseif data then
      if data.playerID then
          print("Game center initialized:", data.alias, data.playerID)
          login_cb_complete = true
      end
  end
end

.....
if gamecenter then gamecenter.login(login_cb) end

gamecenter.reportScore(param)

Parameter Type Description
param table

.

Report score to a specifed Leaderboard

Examples

if login_cb_complete then 
  gamecenter.reportScore({leaderboardId = "com.example.gamecenter.leaderboardId", score = score}) 
end

gamecenter.showLeaderboards(param)

Parameter Type Description
param table

.

Show a specified Leaderboard

Examples

Check gamecenter login complete before calling any method.

if login_cb_complete then 
  gamecenter.showLeaderboards({leaderboardId="com.example.gamecenter.leaderboardId", timeScope = gamecenter.LEADERBOARD_TIME_SCOPE_WEEK})
  -- or show all
  gamecenter.showLeaderboards()
  -- or
  gamecenter.showLeaderboards({timeScope = gamecenter.LEADERBOARD_TIME_SCOPE_WEEK})
end

gamecenter.showAchievements()

Show achievements

Examples

if login_cb_complete then 
  gamecenter.showAchievements()
end

gamecenter.submitAchievement(params)

Parameter Type Description
params table

.

Submit Achievement

Examples

if login_cb_complete then 
  gamecenter.submitAchievement({identifier="com.example.gamecenter.achievementA", percentComplete=45.0})
end