Skip to content

Google Play Games

MrStahlfelge edited this page Jun 27, 2017 · 21 revisions

Google Play Games is a games service primarily used on Android devices. It is a must-have for any Android-capable game.

Overview

Google Play Games belongs to the Google Play services, so you have to get a Google Developer Account and upload your signed APK to the Play Store in order to set it up. It does only work with a correctly signed app then.

Google Play Games supports the following features:

  • Achievements
  • Leaderboards
  • Events
  • Cloud save
  • Real time and turn based multiplayer

Configure your Play Games project

Configure the project like expained in step 2 of Google's Getting started tutorial.

Usage in your libGDX project.

Add the dependency to your Android project:

compile "de.golfgl.gdxgamesvcs:gdx-gamesvcs-android-gpgs:$gamsvcsVersion"

Note that this dependency declares dependency to play services libraries. You can override the version with Gradle project properties, if needed.

Add the following lines to your AndroidManifest.xml and insert the following lines:

<meta-data android:name="com.google.android.gms.games.APP_ID"
    android:value="@string/app_id" />
<meta-data android:name="com.google.android.gms.version"
   android:value="@integer/google_play_services_version"/>

Of course then you need to add your App ID from the Developer Console in your res/value/strings.xml:

<string name="app_id">yourAppIdHere</string>

Change your AndroidLauncher to use the GpgsClient and initialize it:

    GdxGame game = new GdxGameSvcsApp();
    game.gsClient = new GpgsClient().initialize(this, false);
    initialize(game, config);

Don't forget to inform the gpgsClient about activity callbacks. Add the following to your AndroidLauncher:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    gpgsClient.onGpgsActivityResult(requestCode, resultCode, data);
}

(work in progress!)

Clone this wiki locally