Skip to content

Google Play Games (HTML)

Benjamin Schulte edited this page Dec 28, 2017 · 13 revisions

Please see Google Play Games wiki article for an overview. This article describes the differences to use GPGS in your HTML project.

Overview

Google Play Games is not only available for Android, it is possible to use it with a REST API. While GPGS is mainly used on Android, its usage outside the mobile world is not widespread. But by using GPGS in your HTML clients, you can give your users platform-independant cloud save, achievements and leaderboards experience. Not provided by this implementation, it is even possible to provide platform-independant multiplayer games (turn-based).

Configure your Play Games project

Configuration according to Android article is presumed.

For html-gpgs, it is needed to add a linked app of type "Webapp" in GPGS developer console. Google generates an oauth id and a secret client key. The secret client key is not needed for client-only access, but you have to whitelist domain names that are allowed to access the API with your client id. This means: If you release your game on a domain other people can upload to, they can access the Play Games API pretending to be you. This is the case for example on GameJolt, while it is not on Kongregate (they give each game an own subdomain).

Usage in your libGDX project

Include the implementation in your build.gradle for your HTML5 project:

    compile "de.golfgl.gdxgamesvcs:gdx-gamesvcs-html-gpgs:$gamesvcsVersion"
    compile "de.golfgl.gdxgamesvcs:gdx-gamesvcs-html-gpgs:$gamesvcsVersion:sources"

Please note that the implementation is only available with release 0.2.1 and above.

Add Google's JS library to your webapp/index.html:

   <script src="https://apis.google.com/js/api.js"></script>

Now you can use GpgsClient in your HTMLLauncher class. First call initialize() to set your OAuth Client ID. Example project's GPGS branch provides a working example.

Cloud save

If you use cloud save, please note that due to restrictions in libGDX' GWT backend you may not pass in binary data. If you want to store binary data, this is possible by using Base64Coder before saving and after loading your data. The implementation does not handle this for you automatically to preserve data interchangability with GPGS-desktop and for compatibility with future versions when GwtNet supports binary data.

What work is undone?

See issues