Advertisement

Here continues my tutorial on how to add Google Play Services (Leaderboards and Achievements) to your Android Games made with Game Maker: Studio.

This tutorial refers to GameMaker Studio version above 1.4 If you are still using GameMaker v 1.3 first of all you should update it but if you really have to use it refer to this tutorial.

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. From Game Maker v. 1.4 Google Play Services functionality has been taken out the tool and an extension is needed to use Google Play Services. Let’s download Google Play Services Extension from YoYoGames Marketplace: click on MarketPlace Beta, then Marketplace again and search for Google Play Services as Extension.

GPG Extension

Once the extension has been downloaded you should see it under My Library tab. Simply press Add to Project button and you are ready to go!

addto

Just in case you cannot download the extension from the marketplace you can download it here and import into GameMaker the “old way“: right-click on the Extension folder, select Import extension and upload the GooglePlayServicesExtension.extension.gmx file you have found inside the .zip archive.

If this is the first time you use Google Play Services functionality with the extension be sure you have installed Google Repository in Android SDK Manager -> Extras. If not check it, download and install, otherwise the extension will not work.

repository

Now let’s 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.

a

The new extension automatically the logs in Google Play Service at start up so we don’t need to add any code. If you are migrating from the previous version remove the function achievement_login() you should have placed somewhere in your starting scene.

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()

or

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:

err

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 add a comment or contact me if you need any help!

Advertisement