Wednesday 19 March 2014

Game Maker Studio Tutorial - Make your first Android Game #2 : Google Play Service

First of all, I assume that you already have a Google Play Developer Account

If not, visit https://play.google.com/apps/publish/signup/ to register an account.

The one-time fee is $25. It takes about 2-3 business day to finish the registration process

Once complete, now you’re into the Google Play Dev Console.

So in this tutorial, I'll show you how to upload the APK file and set up Google Play Services.

Upload APK file to Google Play

1.    Add new Application

Navigate to the first tab on the left side, you can see this button "Add new application". Click it.

A popup appears. Add the title of your game and the default language.

Then, choose “Upload an APK” to continue.
Add new Application

Upload APK file

2.    Upload APK file to Beta channel

I don’t know much about the difference between Alpha or Beta channel, but since you’re in the testing phase, you should upload the APK file to either channel ( not the Production channel )

In this case, I choose the Beta Channel.

Select and upload your APK file.

Once it’s ready, now go to the next step.

Upload to Beta Channel
Until now, if you don't want to use Google Play Services for your game, you can start testing and ignore the latter steps.

If not, please continue.

3.    Set up the Google Play Service

Please remember, the Google Play Service is not a game, it just the supporting service for your game’s social features, for example : Leaderboard, achievement.

Again, if you don’t want to have these features, then just ignore this step.

  • Navigate to the second tab which has the gamepad icon
  • Click “Add a new game”
  • Choose “ I don’t use any APIs in my game yet”
  • Add the name of your game, choose it category, then click “Continue”
Add Game Service





4.   Inside the Google Play Service window

There’re six steps to be done before publishing any Google Play Service.

See the string next to the game’s name ? It’s the App ID, copy it for later use.
Inside Google Play Service & Application ID


  • Game details : similar to the “Product Listing” tab , you can copy and paste the details
  • Linked App : this is where we can integrate Google Play Service in the game.
  • Achievements and Leaderboards : these are features of the Google Play Service, I’ll show you how to add the Leaderboard, the achievement is pretty much the same
  • Testing : where you can add the testers of the game
  • Publish : once all of these steps are completed, it’s ready to publish the service.
Important note

In order to test the features of Google Play Services, the testing account MUST have a Google+ ( Google Plus ) account available. You can register one at plus.google.com

5.    Link the app

OK, now you go to the second step ( Linked app )

  • Choose the “Android” option, you will see another window.
  • Add the name of your game
  • Choose the package name : just click the field and you will see your previous uploaded APK, click to choose it.
  • Disable the Anti privacy : if it’s enabled, you’ll have errors testing your game.
  • Once done, click “Save and Continue”
Linked App

Linked App Details
You’ll be shown to next step : Authorized your App
Authorize your App

Click this button, there’s popup that requires you to fill in some info. If you don’t have enough resource ( like product logo or homepage ), just ignore them and click “Continue”


OK, now you have to give the SHA1 key

Fill the SHA1 key

  • Come back to GMS-Preferences –Android
  • Navigate to Keystore file, click the Show Key Hash.
  • Copy the string in Key Hash ( SHA 1 ) and paste it to Google .
  • Once done, click “Create Client”, wait a bit.
Congratulations ! You’ve linked your app.


6.    Add the Leaderboard

So, in order to add the leaderboard, go to the fourth part “ Leaderboard”
Add Leaderboard
  • Click to add the leaderboard, you’ll see another window
  • First, supply the name of this leaderboard, this name will be shown to players. You can call it “Highscore”, “Top ten”,etc …
  • Second is the score formatting, normally we choose Numeric, with no decimal value.
  • If you supply no icon, then it will use Google default icon for this
  • Ordering : “Larger is better” : the larger value will stay at the top, while “Smaller is better” has reversed effect.
  • The rest is left default.
  • Once done, click “Save”, you can see a string next to the Leaderboard’s name, copy it for later use.



7.    Integrate the Leaderboard in our game

  • Go back to GMS, navigate to Global Game Settings-Android-Social tab
  • Choose “Enable Google Services”, add the App ID ( next to the game name ) to the box.
OK, it’s done.

8.    Connect to Leaderboard

Now all things are set up, we just need to add some code. It's easy.

Now, go to your GMS.

Put an object in the very first room ( usually the room for Menu ). This object uses no sprite.

Go to Add Event -> Other -> Game Start

Go to Control tab ( in the right ) and pick the “Use some code “

Insert the following code

if os_is_network_connected()
{
    if (!achievement_login_status())
    {
        achievement_login()
    }
}   

This code will log you into the Google Play Service

Traditionally, in the game, you will have two buttons. Use these codes, they will be executed when you press the button

Show Leaderboard button
if achievement_available()
               {
                achievement_show_leaderboards();
}
Submit score to Leaderboard
if achievement_available()
               {
achievement_post_score("xxx", score);
}
  • “xxx” is the string next to the Leaderboard, remember to include the “” because it’s a string.
  • Score is the var which holds the scoring value in your game.

This is the very basic steps, in my game however, I gather all of the code into one button.

The code is as follow
if os_is_network_connected()
        {
            if (!achievement_login_status())
                {
            achievement_login()
                }
             if achievement_available()
               {
                achievement_show_leaderboards();
                achievement_post_score("xxx", score);
               }
        } 

Note
Google doesn’t allow you to publish your game unless you provide at least 5 achievements.

If your game doesn’t have any achivement, you could add 5 achievements in the game.

Remember to choose the “Hidden” option in “Initial state” so the achievement doesn’t show up in your game.

26 comments:

  1. Hello Tom. Thanks for writing this post! By the way, what is the value should i put for "xxx"?

    ReplyDelete
  2. Thank you Jason, sorry for my late response ( busy making my new game :D )

    "xxx" is the string unique to each Leaderboard.

    You can get one by creating a Leaderboard ( Go to Game Services -> Leaderboard ).Follow my guide at point 6.Add the Leaderboard

    To be more precise, it's the string under the ID field, next to the name of the Leaderboard.

    Hope it helps.

    ReplyDelete
  3. I put code to my game but it doesnt post score. Why?

    ReplyDelete
    Replies
    1. Hi Jakub,

      I can't tell you exactly where the problem is based on the question, but,

      I recommend to follow the first and second post of the series because missing one detail can make the posting stuff un successful.

      Then, you can use the checklist in the third post of this series to track down the cause.

      http://gamedesignerkid.blogspot.com/2014/03/game-maker-studio-tutorial-make-your_9706.html

      Popular reasons are :
      _ No Internet connection : rarely, but we sometimes forget to check this out.
      _ You don't add your email as the testing account.
      _ The testing account didn't sign out from Google plus app ( if any )

      Delete
  4. Woww My Fvrt Tool Game Maker Studio 1.4 Crack Mostly need this good job addmin Nice post i would like to add an other mirror for Game Maker Studio 1.4 Crack here
    Remind in your prayers :) :)

    ReplyDelete
  5. Can you tell me how can i get this pop up message when a ach is completed in a game?

    ReplyDelete
  6. Could you please be more specific ?

    ReplyDelete
  7. Hi Tom first time i have seen your site i have to say your tutorials are very clear i like your teachings in what you cover for GMS mobile development wish you had a youtube channel with all of these tutorials though thanks again.

    ReplyDelete
  8. Hi Tom first time i have seen your site i have to say your tutorials are very clear i like your teachings in what you cover for GMS mobile development wish you had a youtube channel with all of these tutorials though thanks again.

    ReplyDelete
  9. I have a problem with not being able to sign into google play services. It says unknown error. Can you or anyone else please leave a response to help me out.

    Thank You, From 2Volts Development

    ReplyDelete
  10. Hi

    For unknown errors, I have no specific solution :). But try these.

    _ Check for your Internet connection : it's one of the most common solution.

    _ Have you published the game in Google Play service yet ?

    Error can happen if you enabled the Google Play in your game, but forgot to publish it in the Google Play service section in Google Dev Dashboard.

    Regards,

    ReplyDelete
    Replies
    1. We have checked for internet connect, made sure the app ID was the same and added to preferences and that the API console for the app had the same SHA1 code. We took your exact same code in order to login in and that's all were trying to make work for right now. We executed the code on a game start event. It has been publish in google play and google play services also the app has been linked on the google play store side and the google services side. Our current version of the app that uses google services is under the beta, is that a problem even though the accounts we sign in with are testers?

      If you can help us out any more that would be greatly appreciated. Also if you like you can email us at rainballapp@gmail.com

      Thank You

      From 2volts Development.

      Delete
  11. I think you can try the following option :

    _ Make sure the tester have the Google+ account
    _ Test the Google Play service by building an APK file, not test using Yoyo Compiler ( it causes error)

    Just emailed the solution :)

    ReplyDelete
  12. Hey how can i add the achievements and hide them because my games has no achievements but a leader-board :)

    ReplyDelete
    Replies
    1. Hi

      It's easy pal.

      The Achievements section is just above the Leaderboard.

      Once you tap to create a new achievement,notice a field called "Initial state".

      Its default value is "Revealed", just change it to "Hidden".

      Remember you can't change the state when the game service is published.

      Delete
  13. after the "achievement_show_leaderboards" section runs how do we control the text and font and so on to create the leaderboard object?

    where is the leaderboard information stored? does "achievement_show_leaderboards" create a DS list or something like that?

    ReplyDelete
  14. I think we can customthe text and font by passing the leaderboard data from Google, however, it's too advanced to me.

    You see, when we show the leaderboard or submit score, we connect to Google Play service, so I don't know how Google store those infos :)
    Cheers

    ReplyDelete
  15. excuesme..please help me.i have any question,,the apk must upload to beta not produksi?thankyou sir

    ReplyDelete
    Replies
    1. Hi

      You must upload the apk file to the Beta Channel to do all the setup for Google Play.

      Once the setup is done, you can move it to the Production.

      Thank you.

      Delete
  16. Hi i did your tutorial and leaderboards post fine but i just cant ever get achievements to work i have buttons that when i touch should post the achievement so that when i goto show achievements it should show all unlocked achievements so far but it never does it always shows locked greyedout achievements never unlocks them no matter how much times i press the unlock buttons. Thanks Any help would be awesome thanks again.

    ReplyDelete
  17. Hi

    Wow, I think it's better if you use some comma :)

    OK, about the Achievement, I think you should check the following :

    Go to each Acheivement, to "Initial State", is that state "Hidden" or "Revealed".

    Because in my tutorial, I don't use Achievement, so I checked it as "Hidden", but once you published the Google Play service, this option can't be changed back to "Revealed" anymore.

    That may cause the problem.

    ReplyDelete
    Replies
    1. Hi Tom all my achievements have always been set to revealed. I test the apk as a alpha tester and leaderboards work but achievements never do they showup when i click show avhievements button but they are always greyed out evn though i have collected the achievements you dont have anymore achievement tutorials or examples to help me learn from at all do you. Thanks Tom

      Delete
    2. Oops didnt do commas :( ;)

      Delete
    3. Also do you have any achievement toast notification tutorials at all. Thanks

      Delete
    4. This comment has been removed by the author.

      Delete
  18. This comment has been removed by the author.

    ReplyDelete