Can you share what you used for leaderboards?
I spent an hour reading through documentation that was all "this module is now deprecated and now split into 2 modules" and "this is the sample code -- does not compile"
I didn't use any
libGDX code to integrate with the Google Play Leaderboards as I only support that on Android and therefore don't need cross-platform Leaderboards.
So instead I just looked at the Google API documentation for leaderboards and achievements and implemented that in a class in my
android project, slapped an interface on that which then allows me to use it from the
core project. For the
desktop project I used a dummy implementation of the interface that does nothing.
Basically this is what I followed
https://developers.google.com/games/services/android/leaderboardsThe obvious downside to this approach is the lack of support on desktop, but if that is not a concern then adding leaderboard support "
directly" by implementing the Google API in the
Activity (or in a class used by the
Activity) is simple.
In the
gradle build file I added
google() to the repositories for
allProjects, then for the
android project I added
compile 'com.google.android.gms:play-services-auth:11.8.0'
compile 'com.google.android.gms:play-services-games:11.8.0'
to the
dependencies.
In my
core project I added an interface that looks sort of like this:
package com.bornander.platformer;
public interface OnlineConnectivity {
void setCallback(OnlineConnectivityCallback callback);
boolean isOnlineCapable();
boolean isSignedIn();
void signIn();
void signInSilently();
void signOut();
void requestTopScores();
void requestAchievements();
void submitScore(int scoreIndex, long score);
void unlockAchievement(int achievementIndex);
void viewLeaderBoards();
void viewAchievements();
}
That interface is then implemented by a class in the
android project (or you can let your Activity implement it) so that it provides the actual implementation, for example:
private GoogleSignInClient signInClient;
private GoogleSignInAccount currentAccount = null;
private LeaderboardsClient leaderboardsClient = null;
private AchievementsClient achievementsClient = null;
@Override // Override onCreate from Activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).build();
signInClient = GoogleSignIn.getClient(this, signInOptions);
}
@Override // Override signInSilently from my OnlineConnectivity interface
public void signInSilently() {
Log.info("signInSilently()");
signInClient.silentSignIn().addOnCompleteListener(this,
new OnCompleteListener<GoogleSignInAccount>() {
@Override
public void onComplete(@NonNull Task<GoogleSignInAccount> task) {
if (task.isSuccessful()) {
try {
Log.info("signInSilently(): success");
currentAccount = task.getResult(ApiException.class);
Log.info("account" + currentAccount);
leaderboardsClient = Games.getLeaderboardsClient(AndroidLauncher.this, currentAccount);
achievementsClient = Games.getAchievementsClient(AndroidLauncher.this, currentAccount);
currentCallback.onlineSignIn();
}
catch(ApiException e) {
Log.info("signInSilently; failed " + e.getMessage());
}
} else {
Log.info("signInSilently(): failure", task.getException());
}
}
});
}