Skip to content

Secludedness: libGDX and Google Play Game Services

After I explained the functionality of the Google Play Game Services in the last post, I’d like to show how to combine libGDX and GPGS. I will demonstrate this on the three supported platforms of Secludedness (Android, Desktop and Browser) and show the problems and difficulties which I’m so far encountered.

General Structure

A game with libGDX is usually split into a core project (Secludedness) for the major game content and platform-specific sub-projects (Secludedness-android, Secludedness-desktop and Secludedness-html). Google Play Game Services uses platform-specific APIs, so it’s necessary to make use of them in each sub-project. The easiest way to solve this in libGDX is to interfacing these APIs with a Facade and provide platform-specific implementations.

In the core project Secludedness, the interface GPGSManager provides all functionality used for GPGS. This includes login, logout ​​and all methods for achievements, leaderboards and cloud save. Into their respective sub-projects concrete implementations for each platform provide the needed functionality. These implementations are instantiated in each main class and passed to the game logic. Because achievements and leaderbords are identified by generated unique IDs the two enums GPGSAchievement and GPGSLeaderboard exist. They provide human-readable names for all achievements and leaderboards with the associated IDs for GPGS.

Android

Android is one of the supported platforms of Google Play Game Services and Google provides a library for its use. This includes activites for the login and to display the achievements and leaderboards in the game. The android project uses the GameHelper class, which is also provided by Google. This class allows an easy access through the Play Service API, including G+ login and the usage of achievements, leaderboards and cloud save. These services are accessed through the AndroidGPGSManager class that implements the GPGSManager interface. The class is also responsible for the conflict resolution, if the data on the client and server are not the same.

The development of the platform-specific implementation for Android was simple and easy to deal with. Google offers a well documented library and a detailed documentation of the usage of Android and GPGS. The integration of the provided APIs in libGDX was also simply to implement and extends only to the MainActivity and the AndroidGPGSManager.

Desktop

Desktop applications developed with Java aren’t officially supported by the Google Play Game Services. Therefore, it’s necessary to self implement a large part of the required steps in comparison to Android. Google provides a zip-file, which contains the necessary libraries (Google and third party) for authentication and data exchange via JSON. There is no Google documentation for the included files, but sometimes external documentation and generated JavaDoc exist.

For the requests, the REST API can be used, which use is actually intended for the browser. The first challenge is the player’s authentication on the G+ service. Google uses OAuth 2.0 to authenticate a user for this service. The zip-file includes the google-api-java-client, which consist of multiple libraries for accessing Google APIs using JSON and OAuth 2.0. Unfortunately, these libraries are only moderately well documented and the sample projects are partially obsolete. After the access token was successfully obtained with this libraries, it must be saved and used for future requests with JSON on the REST API.

For a desktop project the UI itself needs to be build. All informations must be entered in self-created forms (including validation) and displayed in self-created dialogs (e.g. achievements and leaderboards). This increases the development effort significantly.

The current development version of Secludedness doesn’t support yet all the necessary steps for authentication and data exchange with Google Play Game Services. During the development there were repeated problems when trying to exchange the credentials for the OAuth token, so that as a result the player couldn’t get access to the needed data. At the moment a stub implementation (DesktopGPGSManager) is used in the master branch, which generates only log outputs on console. In further versions, this should be replaced by a reliable working solution.

Browser

Google Play Game Services supports Browser based JavaScript games using the REST API. Since Secludedness is developed in Java and a cross-compiling is done with GWT to Javascript, this APIs can be used only with some effort. GWT allows the usage of handwritten JavaScript and the calling of java methods from handwritten JavaScript to return back the results. Due to problems with the integration of the handwritten Javascript files, this approach has not yet been successfully implemented. In addition a bug appeared sometimes when UI elements should be displayed causing in a browser crash. Because the browser game, just like the desktop version, needs custom forms and dialogs to display data, this bug was a blocker in the integration of GPGS. The cause of the crash has yet to be determined to continue the development of this platform. At the moment a stub implementation (GWTGPGSManager) is used in the master branch, which generates only log outputs on console.

As a further possibility the existing Java libraries could be used. Unfortunately, cross-compiling of the provided desktop or android libraries isn’t possible due to the limitations of the GWT cross-compiler (e.g. no reflection).

Current Status

In the current master branch appropriate structures are implemented to use GPGS for all three supported platforms. Because of the problems described above, however, this support isn’t implemented completely so far. The Android version is the only platform that offers all the functionality. In the further development, these problems should be addressed so that a full support of the Google Play Game Services could be achieved.

Published inDevelopment

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *