LEVEL UP!

A better gaming experience with Play Games Services

Your speaker: +StefanHoth / @stefanhoth

Player 1 joined

Play Games Services

Inventory

#io13

#io14

C++

All (important) platforms

What's inside?

Achievements!

Leaderboards!

Quests!

Cloud Save!

Multiplayer!

Gifts!

Anti Piracy!

There's an app for that

Level 1

Press play to join

on Android

  • Android development environment ready (SDK, IDE, ...)
  • A device with Android 2.3+
  • Current Google Play Services installed on the device
  • Activated Google Play Developer account (US$25)

Step 0

Android SDK Manager

> Extras

> install "Google Repository" &

"Android Support Repository"

Step 1: Set up for gradle

dependencies {
    compile 'com.google.android.gms:play-services-games:8.1.0'
 
   //optional for multiplayer matchmaking
    compile 'com.google.android.gms:play-services-plus:8.1.0'
   
    //optional for "Nearby Players" matchmaking
    compile 'com.google.android.gms:play-services-nearby:8.1.0'
}

Add to build.gradle

Sync!

Step 2: Configure Proguard

<3 Thanks, Google! 

https://play.google.com/apps/publish/

Step 3: Google Play Developer Console

Step 4: Add a game

Step 5: Link game

Step 6: Generate OAuth2 client ID

Setup complete!

Level 2

Rewarding players for their engagement

Achievements

States

Incremental achievements

Create an achievement

Check the ids

Code!

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest>
    <application>
        
        // Activities, Services etc go here
        
        <meta-data
          android:name="com.google.android.gms.version"
          android:value="@integer/google_play_services_version" />
        <meta-data
          android:name="com.google.android.gms.games.APP_ID"
          android:value="@string/app_id" />

    </application>
</manifest>

AndroidManifest.xml

Get a client instance


gamesApiClient = new GoogleApiClient.Builder(activity)
                    .addApi(Games.API)
                    .addScope(Games.SCOPE_GAMES)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .build();

Unlock normal achievement


Games.Achievements.unlock(gamesApiClient, "CgkInsXxu-kVEAIQAQ");
// wait, use string resources! 

Increment achievement


Games.Achievements.increment(gamesApiClient, 
   "CgkInsXxu-kVEAIQBA", 1);

Display achievements


startActivityForResult(
    Games.Achievements.getAchievementsIntent(gamesApiClient), 
    REQUEST_CODE_ACHIEVEMENTS);

Display achievements

Level 3

See your global rank or challenge friends

Leaderboards

Create a leaderboard

Code!

Submit a score


Games.Leaderboards.submitScore(
    gamesApiClient, 
    "CgkInsXxu-kVEAIQBw", 
    1337);

Display leaderboard


startActivityForResult(
   Games.Leaderboards.getLeaderboardIntent(
       gamesApiClient, "CgkInsXxu-kVEAIQBw"
   ), 
   REQUEST_CODE_LEADERBOARD);

Display leaderboard

Level 4

Track player success and (re)engange users

Events & Quests

Create an event

Create a quest

Reward data


{
    "bonusGems": 2134,
    "extraSeconds": 12
}

Code!

Submit an event update


Games.Events.increment(gamesApiClient, "CgkInsXxu-kVEAIQCQ", 1);

Display available Quests


startActivityForResult(
   Games.Quests.getQuestsIntent(
       gamesApiClient, Quests.SELECT_ALL_QUESTS
   ), 
   REQUEST_QUESTS);

Level 5

Enable your players to continue

the game on another device

Cloud Save

Google Drive Appfolder

Built-in offline support

Activate Save Games

Save game parts

Unstructured

Structured

{
    "id": 123,
    "name": "Level 2-3",
    "description": "66% already solved",
    "last_modified": 1445401740, // timestamp
    "played time": 31337, // in ms
    "cover_image": 1010101001// bitmap
}

Code!

Set the API

// Google API Client with access to Plus, Games, and Drive
gamesApiClient = new GoogleApiClient.Builder(this)
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this)
    .addApi(Games.API).addScope(Games.SCOPE_GAMES)
    .addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
    .addApi(Drive.API).addScope(Drive.SCOPE_APPFOLDER)
    .build();

Display the saved games

private static final int RC_SAVED_GAMES = 9009;

private void showSavedGamesUI(boolean allowAdd, boolean allowDelete) {

    int maxNumberOfSavedGamesToShow = 5;
    Intent savedGamesIntent = 
        Games.Snapshots.getSelectSnapshotIntent(gamesApiClient,
            "See My Saves", allowAdd, allowDelete, maxNumberOfSavedGamesToShow);
    startActivityForResult(savedGamesIntent, RC_SAVED_GAMES);
}

Save game parts

private PendingResult<Snapshots.CommitSnapshotResult> writeSnapshot(Snapshot snapshot,
        byte[] data, Bitmap coverImage, String desc) {

    
}

Save game parts

private PendingResult<Snapshots.CommitSnapshotResult> writeSnapshot(Snapshot snapshot,
        byte[] data, Bitmap coverImage, String desc) {

    // Set the data payload for the snapshot
    snapshot.getSnapshotContents().writeBytes(data);

}

Save game parts

private PendingResult<Snapshots.CommitSnapshotResult> writeSnapshot(Snapshot snapshot,
        byte[] data, Bitmap coverImage, String desc) {

    // Set the data payload for the snapshot
    snapshot.getSnapshotContents().writeBytes(data);

    // Create the change operation
    SnapshotMetadataChange metadataChange = new SnapshotMetadataChange.Builder()
            .setCoverImage(coverImage)
            .setDescription(desc)
            .build();
}

Save game parts

private PendingResult<Snapshots.CommitSnapshotResult> writeSnapshot(
        Snapshot snapshot, byte[] data, Bitmap coverImage, String desc) {

    // Set the data payload for the snapshot
    snapshot.getSnapshotContents().writeBytes(data);

    // Create the change operation
    SnapshotMetadataChange metadataChange = new SnapshotMetadataChange.Builder()
            .setCoverImage(coverImage)
            .setDescription(desc)
            .build();

    // Commit the operation
    return Games.Snapshots.commitAndClose(gamesApiClient, snapshot, metadataChange);
}

Game On DevByte

Shortcuts

Attention: Publish twice!

All ids in one go

All ids in one go

Magic?

Boss level

Publishing API

Create & Update

achievements + leaderboards

Management APIs

  • Reset scores, achievements, quests etc.
  • only for testers and unpublished games
  • after release: hide cheaters from leaderboards

/playgameservices/management-tools

Player Analytics

Secret bonus level

Google Tag Manager

GAME OVER

Questions

Play Games Services Docs

https://developers.google.com/games/services/

//TODO: Ropasc Lisc on GitHub

https://github.com/stefanhoth/ropasclisp

Thank You!

Stefan Hoth

stefan@novoda.com

@stefanhoth

+StefanHoth

stefanhoth

Sources

Made with Slides.com