将 XP 添加到 Android 个游戏应用
Add XP to Android game app
我已经制作了一个游戏应用程序,现在我想添加 google 成就 xp 到我的应用程序我应该怎么做 我已经使用这个 guide 添加了成就
但是我在互联网上找不到应该添加玩家获得的经验值的指南。
这是我解锁成就的代码,但它没有解锁 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);
}
}
}
XP 不是基于您的游戏,而是基于您的 Google+ 个人资料。假设您在游戏 Orc Genocide 中解锁了一项成就,并且您的 Google+ 个人资料获得了 500xp。之后,您在游戏中解锁一项成就并获得 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
When you get in-game achievements, you can earn experience points (XP)
and levels on your Play Games profile.
When you're playing a game, you'll see a notification when you've
earned XP or enough points to level up your Play Games profile. When
you level up, you'll also see a notification in your mobile device's
notification shade near the top of your screen and your Play Games
Inbox menu.
You can view your XP and individual achievements on games you use with
Play Games on your Play Games profile page.
For more information on how to make your Game Profile public or
private, go to Play games on your device.
我已经制作了一个游戏应用程序,现在我想添加 google 成就 xp 到我的应用程序我应该怎么做 我已经使用这个 guide 添加了成就 但是我在互联网上找不到应该添加玩家获得的经验值的指南。
这是我解锁成就的代码,但它没有解锁 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);
}
}
}
XP 不是基于您的游戏,而是基于您的 Google+ 个人资料。假设您在游戏 Orc Genocide 中解锁了一项成就,并且您的 Google+ 个人资料获得了 500xp。之后,您在游戏中解锁一项成就并获得 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
When you get in-game achievements, you can earn experience points (XP) and levels on your Play Games profile.
When you're playing a game, you'll see a notification when you've earned XP or enough points to level up your Play Games profile. When you level up, you'll also see a notification in your mobile device's notification shade near the top of your screen and your Play Games Inbox menu.
You can view your XP and individual achievements on games you use with Play Games on your Play Games profile page.
For more information on how to make your Game Profile public or private, go to Play games on your device.