The gamecenter module provides simple support for the iOS Game Center framework. More...
| Methods: |
|
| Functions: |
|
To use GameCenter in your game:
#If TARGET<>"ios"#Error "GameCenter is only available on iOS"#EndImport mojoImport brl.gamecenterClass 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 EndFunction Main() New MyAppEndReturns one of the following values:
| State | Meaning |
|---|---|
| -1 | Error : Game Center cannot be used |
| 0 | Game Center is available but has not been started yet |
| 1 | Game Center has started and is busy connecting |
| 2 | Game Center has successfully connected and is awaiting further instructions |
| 3 | A leaderboard is currently showing |
| 4 | Game achievements are currently showing |
Report an achievement to Game Center.
The achievement_ID parameter should match the achievement ID specified in iTunes connect when the achievement was created.
Report a score to Game Center.
The leaderboard_ID parameter should match the leaderboard ID specified in iTunes connect when the leaderboard was created.
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.
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.
Starts Game Center.
Once started, you should wait until GameCenterState returns 2 before using any Game Center functionality.