如何在libGDX游戏中使用Scoreloop的奖励系统

时间:2013-03-29 10:20:00

标签: java android libgdx scoreloop

我想在游戏中使用Scoreloop成就。我在其网站上配置了包含图标的捆绑包,并将捆绑包添加到资产当运行Scorellop EntryActivity时,我有成就活动。但是现在我需要从我的游戏中取得成就进展,但我无法理解它是如何做到的。来自Scoreloop网站的文档不会为我清除。有人可以提供示例代码吗?

1 个答案:

答案 0 :(得分:3)

 public void achieve(final String awardId) {
    ScoreloopManagerSingleton.get().loadAchievements(null);

    // final String awardId = context.getResources().getString(resId);

    // i.e. wait with the unlocking and/or display of achievements until your runnable gets invoked.
    ScoreloopManagerSingleton.get().loadAchievements(new Continuation<Boolean>() {
      @Override
      public void withValue(Boolean arg0, Exception arg1) {
        Achievement achivment = ScoreloopManagerSingleton.get().getAchievement(awardId);
        if (achivment.getAward().getAchievingValue() - achivment.getValue() == 1) {
          ScoreloopManagerSingleton.get().achieveAward(achivment.getAward().getIdentifier(), true, true);
        } else {
          if (!achivment.isAchieved()) {
            achivment.incrementValue();
          }

          if (achivment.needsSubmit()) {
            AchievementController aController = new AchievementController(
                new RequestControllerObserver() {

                  public void requestControllerDidReceiveResponse(RequestController arg0) {
                    // TODO Auto-generated method stub

                  }

                  public void requestControllerDidFail(RequestController arg0, Exception arg1) {
                    // TODO Auto-generated method stub

                  }
                });

            aController.setAchievement(achivment);
            aController.submitAchievement();
          }
        }
      }

    });
  }