2015-05-11 106 views
1

我的場景:可以說我有3個成就。我增加1成就,當完成時我想增加2成就等等。在android中的成就增加成就

1)如何成就之間切換,繼續增量

2)有沒有辦法讓我不得不增加

3,成績)有沒有辦法改變的外觀和感覺'Games.Achievements.getAchievementsIntent'視圖?

4)如果我想在特定成就後啓用應用程序內購買,我該怎麼做?

感謝

回答

0

首先加載的成就(見Google Play Game Services get achievements list

其次,遍歷所有成就和看到所有的增量成果和最高成就解鎖。然後決定下一步增加哪個增量成就(achivementId)。

最後,使用此代碼重新加載成就,當一個已被解鎖。

Games.Achievements.incrementImmediate(mGoogleApiClient, achivementId, 1) 
       .setResultCallback(new ResultCallback<Achievements.UpdateAchievementResult>() { 

        @Override 
        public void onResult(Achievements.UpdateAchievementResult result) { 
         switch (result.getStatus().getStatusCode()) { 
          case GamesStatusCodes.STATUS_ACHIEVEMENT_UNLOCKED: 
          loadAchievements(); // load achivments and decide which one to increment next 
           break; 
          case GamesStatusCodes.STATUS_ACHIEVEMENT_UNKNOWN: 
           // the achievement failed to update because could not find the achievement to update. 
           break; 
          case GamesStatusCodes.STATUS_ACHIEVEMENT_NOT_INCREMENTAL: 
           // achievement failed to increment since it is not an incremental achievement. 
           break; 
          case GamesStatusCodes.STATUS_ACHIEVEMENT_UNLOCK_FAILURE: 
           // the call to unlock achievement failed. 
           break; 
         } 
        } 

       }); 
1

要做到這一切,你必須做出一個函數,它接受一個參數,像下面給出的一個:

public boolean unlockAchievement(int whichAchievement) 

    { 
    switch(whichAchievement) 
{ 
case 1: 

     achievementId = mainActivity.getString(R.string.achievement_id_1); 
     achievementCause = mainActivity 
       .getString(R.string.achievement_cause_1); 
     break; 
    case 2: 
     achievementId = mainActivity.getString(R.string.achievement_id_2); 
     achievementCause = mainActivity 
       .getString(R.string.achievement_cause_2); 
//Enable inapp purchase here 
     break; 
    } 

    AchievementsClient acClient = mainActivity.agsClient 
      .getAchievementsClient(); 
    AGResponseHandle<UpdateProgressResponse> handle = acClient 
      .updateProgress(achievementId, 100.0f); 

    // Optional callback to receive notification of success/failure. 
    handle.setCallback(new AGResponseCallback<UpdateProgressResponse>() { 

     @Override 
     public void onComplete(UpdateProgressResponse result) { 
      if (result.isError()) { 
       // Toast.makeText(mainActivity, 
       // "Something is wrong and achievement is not unlocked", 
       // Toast.LENGTH_LONG).show(); 
      } else { 
       // Toast.makeText(mainActivity, 
       // "Achievement unlocked successfully", 
       // Toast.LENGTH_LONG).show(); 
      } 
     } 
    }); 

調用此函數,只要你解開的成就。答對了!使用
Games.Achievements.load

+0

感謝您的回答,如果我啓用這樣的應用內購買,那麼將成就ID存儲在資源文件中是明智的。這不是一個安全問題,因爲用戶可以訪問資源文件。 – pats

+0

不,總是將所有這些信息存儲在res/strings中的好習慣。 – nullPointerException

+0

如果您通過單擊勾號按鈕解決了問題,則可以將答案標記爲正確:) – nullPointerException