Cerberus X Documentation

Class GameCenter

The gamecenter module provides simple support for the iOS Game Center framework. More...

Declarations

Methods
GameCenterAvail : Bool () Returns true if Game Center support is available.
GameCenterState : Int () Returns one of the following values:
ReportAchievement : Void ( percentComplete:Float, achievement_ID:String ) Report an achievement to Game Center.
ReportScore : Void ( value:Int, leaderboard_ID:String ) Report a score to Game Center.
ShowAchievments : Void () Shows game achievements.
ShowLeaderboard : Void ( leaderboard_ID:String ) Shows the leaderboard with the given id.
StartGameCenter : Void () Starts Game Center.
Functions
GetGameCenter : GameCenter () Gets the global GameCenter object.

Detailed Discussion

The gamecenter module provides simple support for the iOS Game Center framework.

To use GameCenter in your game:

  1. Add your game in iTunes connect, Apple's portal for uploading iOS apps - http://itunesconnect.apple.com
    • Enable Game Center support for your game in iTunes connect.
      • Add Leaderboards and/or achievements to your game in iTunes connect.
        • Import brl.gamecenter into your game and use the GameCenter class as required.

            Notes:

            • You must add your app to iTunes connect even if you are just testing/experimenting.
              • You will need to be a registered Apple developer to use iTunes connect and therefore Game Center.
                • Make sure your app's 'Bundle Identifier' in XCode matches the iTunes connect 'Bundle ID' for your app.
                      Example
                      #If TARGET<>"ios"
                      #Error "GameCenter is only available on iOS"
                      #End

                      Import mojo
                      Import brl.gamecenter

                      Class MyApp Extends App

                      Field gamectr:GameCenter

                      Field coins_collected:=0
                      Const coins_total=25

                      Method OnCreate()
                      gamectr=GameCenter.GetGameCenter()
                      gamectr.StartGameCenter
                      SetUpdateRate 60
                      End

                      Method OnUpdate()
                      Select gamectr.GameCenterState()
                      Case 2
                      If MouseHit(0)
                      If Abs( MouseY-DeviceHeight/4 )<16
                      gamectr.ShowLeaderboard "HIGH_SCORES" 'use the Leaderboard ID you specified in iTunes connect here...
                      Else If Abs( MouseY-DeviceHeight/2 )<16
                      gamectr.ShowAchievements
                      Else If Abs( MouseY-DeviceHeight*3/4 )<16

                      random.Seed=Millisecs
                      gamectr.ReportScore Rnd(1000,2000),"HIGH_SCORES"

                      coins_collected+=1
                      gamectr.ReportAchievement coins_collected*100/coins_total,"COLLECT_ALL_COINS" 'use the Achievement ID you specified in iTunes connect here...

                      Endif
                      Endif
                      End
                      End

                      Method OnRender()
                      Cls
                      DrawText "Game Center state="+gamectr.GameCenterState(),DeviceWidth/2,0,.5,0
                      If gamectr.GameCenterState()<>2 SetColor 128,0,0
                      DrawText "Click here to show Leaderboard",DeviceWidth/2,DeviceHeight/4,.5,.5
                      DrawText "Click here to show Achievements",DeviceWidth/2,DeviceHeight/2,.5,.5
                      DrawText "Click here to report Score+Achievement",DeviceWidth/2,DeviceHeight*3/4,.5,.5
                      End

                      End


                      Function Main()
                      New MyApp
                      End

                      Methods Documentation

                      Method GameCenterAvail : Bool ()

                      Returns true if Game Center support is available.

                      Method GameCenterState : Int ()

                      Returns one of the following values:

                      StateMeaning
                      -1Error : Game Center cannot be used
                      0Game Center is available but has not been started yet
                      1Game Center has started and is busy connecting
                      2Game Center has successfully connected and is awaiting further instructions
                      3A leaderboard is currently showing
                      4Game achievements are currently showing
                      Method ReportAchievement : Void ( percentComplete:Float, achievement_ID:String )

                      Report an achievement to Game Center.

                      The achievement_ID parameter should match the achievement ID specified in iTunes connect when the achievement was created.

                      Method ReportScore : Void ( value:Int, leaderboard_ID:String )

                      Report a score to Game Center.

                      The leaderboard_ID parameter should match the leaderboard ID specified in iTunes connect when the leaderboard was created.

                      Method ShowAchievments : Void ()

                      Shows game achievements.

                      While game achievements are showing your game will continue to update (OnUpdate will continue to be called), however GameCenterState will return 4.

                      Method ShowLeaderboard : Void ( leaderboard_ID:String )

                      Shows the leaderboard with the given id.

                      While a leaderboard is showing your game will continue to update (OnUpdate will continue to be called), however GameCenterState will return 3.

                      Method StartGameCenter : Void ()

                      Starts Game Center.

                      Once started, you should wait until GameCenterState returns 2 before using any Game Center functionality.


                      Functions Documentation

                      Function GetGameCenter : GameCenter ()

                      Gets the global GameCenter object.