我制作了一个游戏应用程序,我现在想将谷歌成就xp添加到我的应用程序我应该如何做到这一点我使用此guide添加了成就 但我没有找到互联网上的指南,应该添加玩家获得的xp。
这是我解锁成就的代码,但它没有解锁xp:
void giveAchievements(int counter) {
if (counter == 10) {
if (getApiClient().isConnected()) {
Games.Achievements.unlock(getApiClient(),
getString(R.string.achievement_first_10_clicks));
Games.Leaderboards.submitScoreImmediate(getApiClient(), "CgkI- eXOwZsFEAIQBg", counter);
}
}
if (counter == 50) {
if (getApiClient().isConnected()) {
Games.Achievements.unlock(getApiClient(),
getString(R.string.achievement_50_clicks));
Games.Leaderboards.submitScoreImmediate(getApiClient(), "CgkI-eXOwZsFEAIQBg", counter);
}
}
if (counter == 100) {
if (getApiClient().isConnected()) {
Games.Achievements.unlock(getApiClient(),
getString(R.string.achievement_100_clicks));
Games.Leaderboards.submitScoreImmediate(getApiClient(), getString(R.string.leaderboard_leaderboard), counter);
}
}
if (counter == 250) {
if (getApiClient().isConnected()) {
Games.Achievements.unlock(getApiClient(),
getString(R.string.achievement_250_clicks));
Games.Leaderboards.submitScoreImmediate(getApiClient(), "CgkI-eXOwZsFEAIQBg", counter);
}
}
if (counter == 500) {
if (getApiClient().isConnected()) {
Games.Achievements.unlock(getApiClient(),
getString(R.string.achievement_500_clicks));
Games.Leaderboards.submitScoreImmediate(getApiClient(), getString(R.string.leaderboard_leaderboard), counter);
}
}
if (counter == 1000) {
if (getApiClient().isConnected()) {
Games.Achievements.unlock(getApiClient(),
getString(R.string.achievement_1000_clicks));
Games.Leaderboards.submitScoreImmediate(getApiClient(), getString(R.string.leaderboard_leaderboard), counter);
}
}
if (counter == 1500) {
if (getApiClient().isConnected()) {
Games.Achievements.unlock(getApiClient(),
getString(R.string.achievement_1500_clicks));
Games.Leaderboards.submitScoreImmediate(getApiClient(), getString(R.string.leaderboard_leaderboard), counter);
}
}
if (counter == 3000) {
if (getApiClient().isConnected()) {
Games.Achievements.unlock(getApiClient(),
getString(R.string.achievement_3000_clicks));
Games.Leaderboards.submitScoreImmediate(getApiClient(), getString(R.string.leaderboard_leaderboard), counter);
}
}
if (counter == 5000) {
if (getApiClient().isConnected()) {
Games.Achievements.unlock(getApiClient(),
getString(R.string.achievement_5000_clicks));
Games.Leaderboards.submitScore(getApiClient(), getString(R.string.leaderboard_leaderboard), counter);
}
}
}
答案 0 :(得分:2)
XP并非基于您的游戏,而是基于您的Google+个人资料。假设您在游戏Orc Genocide中解锁了一项成就,并且您获得了500xp的Google+个人资料。之后,您将在游戏中解锁一项成就并获得1000xp。因此,您的Google+个人资料总计为1500xp。
但您可以自己轻松计算XP并将其存储在SharedPreferences:)
中void giveAchievements(int counter) {
if (counter == 10) {
int xp = getXp();
xp += 500;
saveXp(xp);
if(getApiClient().isConnected()) {
Games.Achievements.unlock(getApiClient(), getString(R.string.achievement_first_10_clicks));
Games.Leaderboards.submitScoreImmediate(getApiClient(), "CgkI- eXOwZsFEAIQBg", counter);
}
}
}
private int getXp() {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
return sharedPref.getInt("xp", 0);
}
private void saveXp(int xp) {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt("xp", xp);
editor.apply();
}
https://support.google.com/googleplay/answer/3129940?hl=en
当你获得游戏成就时,你可以获得经验值(XP) 和Play游戏个人资料中的等级。
当你玩游戏时,你会看到通知 获得XP或足够的积分来升级您的Play游戏个人资料。什么时候 升级后,您还会在移动设备上看到通知 靠近屏幕顶部和Play游戏的通知阴影 收件箱菜单。
您可以在使用的游戏中查看自己的XP和个人成就 在Play游戏个人资料页面上玩游戏。
有关如何将您的游戏资料公开或公开的详细信息 私密,请转到您设备上的游戏。