Google GameServices/ Diddy
Monkey Targets Forums/Android/Google GameServices/ Diddy
| ||
| Hi guys, I'm interested in adding GameServices to some apps to allow cool things like Leaderboards. Searching through the threads, it looks like there's this kind of capability in Diddy.. I'm after some example code and/ or hints around this. Thanks in advance, fellow Monkey-er's :-) |
| ||
| It's been awhile since I did it in Diddy, but looking thru my old code: Import the game service Import diddy #If TARGET="android" Import diddy.gameservice #end Create the gameservice object and leaderboard consts Class Game Extends DiddyApp #If TARGET="android" or TARGET="ios" Field gameservice:GameService #End ' leaderboard ids Const LB_SPRINT_25:String = "################" Const LB_SPRINT_50:String = "################" Const LB_SURVIVIAL_NORMAL:String = "################" Const LB_SURVIVIAL_FAST:String = "###############" ... Method Create:Void() ... gameservice = New GameService ... Sign into the gameservice Class TitleScreen Extends Screen
...
Method Start:Void()
...
#If TARGET="android"
If game.gameservice.IsLoggedIn()
cb = New CheapButton(diddyGame.images.Find("icon_trophey"), SCREEN_WIDTH2, y)
cb.SetRGB(255, 0, 0)
cb.actionDelegate = New LeaderDelegate(Self)
Else
cb = New CheapButton(diddyGame.images.Find("icon_trophey"), SCREEN_WIDTH2, y)
cb.SetRGB(255, 0, 0)
cb.actionDelegate = New LeaderSignInDelegate(Self)
End
#end
#If TARGET="android"
If game.googleState = 0
If game.gameservice.IsNetworkAvailable()
If game.gameservice.IsLoggedIn() = False Then
Print "Trying to log in..."
game.gameservice.BeginUserSignIn()
game.googleState = 1
game.SaveGoogleState()
Print "Signing In!"
End
End
End
If game.googleState = 1
If game.gameservice.IsNetworkAvailable()
game.gameservice.BeginUserSignIn()
Print "Signing In On Startup!"
End
End
#End
End
Helper delegates Class LeaderSignInDelegate Extends ActionDelegate
Method New(screen:Screen)
Self.screen = screen
End
Method DoAction:Void(screen:Screen)
Super.DoAction(screen)
#If TARGET="android"
Print "LeaderSignInDelegate"
If game.gameservice.IsNetworkAvailable()
If game.gameservice.IsLoggedIn() = False Then
Print "IsLoggedIn = FALSE"
game.gameservice.BeginUserSignIn()
Else
Print "IsLoggedIn = TRUE"
game.gameservice.ShowAllLeaderBoards()
End
Else
ShowAlertDialog("Check Network", "Please check your network settings.")
End
#end
End
End
Class SignOutDelegate Extends ActionDelegate
Method New(screen:Screen)
Self.screen = screen
End
Method DoAction:Void(screen:Screen)
Super.DoAction(screen)
#If TARGET="android"
game.gameservice.SignOut()
game.googleState = 0
game.SaveGoogleState()
#end
End
End
Class LeaderDelegate Extends ActionDelegate
Method New(screen:Screen)
Self.screen = screen
End
Method DoAction:Void(screen:Screen)
Super.DoAction(screen)
#If TARGET="android"
If game.gameservice.IsNetworkAvailable()
game.gameservice.ShowAllLeaderBoards()
Else
ShowAlertDialog("Check Network", "Please check your network settings.")
End
#end
End
EndSubmit the score to the leaderboard If newBest
#If TARGET="android"
If game.gameservice.IsNetworkAvailable()
If game.gameservice.IsLoggedIn()
If gameMode = STEPPING_25
Print "Submitting game.bestMs25 = " + game.bestMs25
game.gameservice.SubmitHighscore(Game.LB_SPRINT_25, game.bestMs25)
End
If gameMode = STEPPING_50
Print "Submitting game.bestMs50 = " + game.bestMs50
game.gameservice.SubmitHighscore(Game.LB_SPRINT_50, game.bestMs50)
End
End
End
#end
game.SaveScores()
End
I think thats it... sorry for the code snippets but it's been awhile :) |
| ||
| Sir, You are a super star. I will give this a go. Thanks for your help and time. I owe you a pint. Was there/ is there also an .xml file I need to mess around with? |
| ||
| Was there/ is there also an .xml file I need to mess around with? Yeah, I think you are right... Create your Android build and then copy in the ids.xml into the res/values folder: <?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_id">#############</string>
</resources>Then rebuild and cross your fingers :) |