THE FOLLOWING TUTORIAL IS OBSOLETE, IT REFERS TO AN OLD VERSION OF GAMEMAKER (1.3 IF I DON’T REMEMBER WRONGLY). CLICK HERE FOR THE UPDATED TUTORIAL.
Here continues my tutorial on how to add Google Play Services (Leaderboards and Achievements) to you Android Games made with Game Maker: Studio.
At this point you should have already set up everything needed on Google Play Developer Console, if you have missed the first part of this tutorial you can find it here.
So let’s open our project in Game Maker. First time we need to enable Google Play Service, double click on Global Game Settings, open Android tab and Social sub-section. Thick the “Enable Google Service” box and paste the App ID we got on Google Play Dashboard.
Now we have to initiate Google APIs and prompt the player to login to Google Play Service. Place the following code in the create event of an object, normally placed in the first room of the game:
if (!achievement_login_status() achievement_login()
Then we need to send score data to our leaderboard. Place the following code on a left mouse pressed event for a “Send Score” button or on hero’s death event:
if (achievement_available()) achievement_post_score("CgkI_KKgzZoeEAIQAA", points);
where “CgkI_KKgzZoeEAIQAA” id the Leaderboards ID we have copied from Developer Dashboard and points is the variable that stores the current score.
Same way for achievements, in our example we wanted to track coins collected, so let’s put this code in the collision event with the player of our Coin object:
if achievement_available() achievement_increment('CgkI_KKgzZoeEAIQAQ', 1)
this will increment of +1 the “Take 1000 coins” achievement, that will be automatically unlocked when the 1000th coins is collected!
If you have made non-incremental achievements you can simply unlock them with this code:
if achievement_available() achievement_post('CgkI_KKgzZoeEAIQAQ', 100)
where 100 meaning that 100% of the achievement is completed.
We can also create buttons in out Menu to show Leaderboards or Achievements with this simple code in the left pressed event:
if achievement_login_status() achievement_show_leaderboards()
if achievement_login_status() achievement_show_achievements()
We are now ready to test our game and check if Leaderboards and Achievements work as supposed to.
Create the application (you will not be able to test Google APIs without creating an .apk, we cannot simply run game with YoYoRunner) and send it to you Android device (if your device is connected Game Maker will install and launch the App automatically). When prompted connect with your account and you are ready to test!
If you see this error:
much probably you forgot to add your account in Developer Dashboard as Tester; simply go back and check, add your email address and everything should work.
Another reason could be Certificate signature of the uploaded APK and the one you are using are different. Always use the same Keystore certificate and store it somewhere safe for the future or you won’t be able to make updates to your Apps!
Now you should be ready to add Leaderboard and Achievements to all you GAme Maker games for Android!
Thanks for reading this tutorial and don’t hesitate to contact me if you need any help!