Domanda

So I'm writing a java game with Eclipse that uses Google Play Game Services to handle my achievements. I have done everything as in the sample games provided by Google, with the exception that I have added GameHelper directly to my existing activity instead of using BaseGameActivity. Now I have a problem. If a player uses one device to unlock an achievement that actually affects the game, how can I make the other device spot the unlocked achievement?

With a bit of browsing I have found out that I should be using mHelper.getGamesClient().loadAchievements(OnAchievementsLoadedListener listener) and then use that onAchievementsLoaded (int statusCode, AchievementBuffer buffer) listener. The AchievementBuffer buffer seems to contain all the data I want.

Now the problem is that I have no idea how to use this listener. Where should I put it, should I call loadAchievements() or is it called automatically at sign in etc.

It would be great if somebody could help me with this :)

È stato utile?

Soluzione

Indeed, the Achievement buffer will contain all the data you want (if the statusCode returned is STATUS_OK). You can load the achievements "on-demand" from your activity (which extends BaseGameActivity per example) via:

getGamesClient().loadAchievements(new OnAchievementsLoadedListener() {
    @Override
    public void onAchievementsLoaded(int statusCode, AchievementBuffer buffer) {
        if (statusCode == GamesClient.STATUS_OK) {
            int achievementsCount    = buffer.getCount();

            [...]

        }
        buffer.close();
    }
});

And do not forget to close the buffer.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top