Your speaker: +StefanHoth / @stefanhoth
C++
on Android
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
<3 Thanks, Google!
https://play.google.com/apps/publish/
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>
gamesApiClient = new GoogleApiClient.Builder(activity)
.addApi(Games.API)
.addScope(Games.SCOPE_GAMES)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
Games.Achievements.unlock(gamesApiClient, "CgkInsXxu-kVEAIQAQ");
// wait, use string resources!
Games.Achievements.increment(gamesApiClient,
"CgkInsXxu-kVEAIQBA", 1);
startActivityForResult(
Games.Achievements.getAchievementsIntent(gamesApiClient),
REQUEST_CODE_ACHIEVEMENTS);
Games.Leaderboards.submitScore(
gamesApiClient,
"CgkInsXxu-kVEAIQBw",
1337);
startActivityForResult(
Games.Leaderboards.getLeaderboardIntent(
gamesApiClient, "CgkInsXxu-kVEAIQBw"
),
REQUEST_CODE_LEADERBOARD);
{
"bonusGems": 2134,
"extraSeconds": 12
}
Games.Events.increment(gamesApiClient, "CgkInsXxu-kVEAIQCQ", 1);
startActivityForResult(
Games.Quests.getQuestsIntent(
gamesApiClient, Quests.SELECT_ALL_QUESTS
),
REQUEST_QUESTS);
{
"id": 123,
"name": "Level 2-3",
"description": "66% already solved",
"last_modified": 1445401740, // timestamp
"played time": 31337, // in ms
"cover_image": 1010101001// bitmap
}
// 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();
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);
}
private PendingResult<Snapshots.CommitSnapshotResult> writeSnapshot(Snapshot snapshot,
byte[] data, Bitmap coverImage, String desc) {
}
private PendingResult<Snapshots.CommitSnapshotResult> writeSnapshot(Snapshot snapshot,
byte[] data, Bitmap coverImage, String desc) {
// Set the data payload for the snapshot
snapshot.getSnapshotContents().writeBytes(data);
}
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();
}
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);
}
Create & Update
achievements + leaderboards
/playgameservices/management-tools
https://developers.google.com/games/services/
https://github.com/stefanhoth/ropasclisp
Stefan Hoth
stefan@novoda.com
@stefanhoth
+StefanHoth
stefanhoth