【问题标题】:Add XP to Android game app将 XP 添加到 Android 游戏应用程序
【发布时间】:2016-05-31 09:01:39
【问题描述】:

我已经制作了一个游戏应用程序,我现在想将 google 成就 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);
        }
    }
}

【问题讨论】:

  • 如果我的回答解决了您的问题,请考虑通过单击复选标记接受它。这向更广泛的社区表明您已经找到了解决方案,并为回答者和您自己提供了一些声誉。没有义务这样做。
  • @SimonSchubert 你真的是一个救生员,谢谢!
  • 很好用!
  • @SimonSchubert 但它现在崩溃了
  • @SimonSchubert 现在显示此错误 发送崩溃报告时出错 ait:服务器未收到报告:来源 错误消息:移动崩溃和性能报告 API 尚未在项目 admob-app-id- 中使用6652174517-638fe 之前或已禁用。

标签: android android-studio google-play-services achievements


【解决方案1】:

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

当您获得游戏内成就时,您可以获得经验值 (XP) 和您的 Play 游戏个人资料中的级别。

在玩游戏时,您会在玩游戏时看到通知 获得 XP 或足够积分来升级您的 Play 游戏个人资料。什么时候 您升级后,您还会在移动设备的 靠近屏幕顶部和 Play 游戏的通知栏 收件箱菜单。

您可以在您使用的游戏中查看您的 XP 和个人成就 在您的 Play 游戏个人资料页面上玩游戏。

有关如何公开您的游戏资料的更多信息或 私密,请转到在您的设备上玩游戏。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多