Leaderboard

 

This section explains the integration details of using Leaderboard feature.

1. Prerequisites

The steps required before the use of leaderboard in game

2. Submit Player Score

Call the method KTLeaderboard.reportScore to submit player score.
Parameters:

  • score : Player score
  • leaderboardId : The identifier of leaderboard to submit score to.
  • scoreTag : preserved. null or empty string "" can be used.
  • listener/callback : A Listener/Callback to handle score reporting result if necessary.

 //Define a Callback to handle score reporting result if necessary.
KTLeaderboard.OnReportScoreListener onReportScoreListener = 
new KTLeaderboard.OnReportScoreListener(){
    @Override
    public void onReportScoreResult(boolean isSuccess, 
    String leaderboardId, long score, String scoreTag, KTError error) {
        if(isSuccess){
            //success
        }else{
            //failed
        }               
    }
};

//Report Score
KTLeaderboard.reportScore(100, "Your Leaderboard ID", scoreTag, onReportScoreListener);

//Report Score
 [KTLeaderboard reportScore:1000 leaderboardId:@"Your Leaderboard ID"  success:^{
      //success
  } failure:^(NSError *error) {
     // failed
}];

 //Define a Callback to handle score reporting result if necessary.
static void reportScoreCallback(bool isSuccess,const char *leaderboardId,long long score, char *scoreTag, KTErrorC *error)
{
    if (isSuccess) {
        // success
    } else {
        // failed
    }
}

//Report Score
KTLeaderboardC::reportScore(100010, "Your Leaderboard ID", "scoreTag", reportScoreCallback);

 //Define a Callback to handle score reporting result if necessary.
void onLeaderboard(string param) {
    KTLeaderboard.KTLeaderboardCallbackParams leaderParams
        = new KTLeaderboard.KTLeaderboardCallbackParams(param);
    
    switch(leaderParams.leaderboardEventResult) {
        case KTLeaderboard.KTLeaderboardCallbackParams.KTLeaderboardEvent.KTPlayLeaderboardEventReportScore:{
                    }
        break;
        case KTLeaderboard.KTLeaderboardCallbackParams.KTLeaderboardEvent.OnKTError:{
            KTError error = (KTError) leaderParams.playError;
            
        }
        break;
    }
}
//Report Score
KTLeaderboard.ReportScore(20000, "Your Leaderboard ID", "scoreTag", this,this.onLeaderboard);

 //Define a Listener to handle score reporting result if necessary.
public function reportScoreListener(isSuccess:Boolean,error:KTError,requestInfo:Object):void{
            if(isSuccess){
                 // success
            }else{
                 // failed
        }
// Report Score
KTLeaderboard.reportScore(score,"Your Leaderboard ID",tag,reportScoreListener);

 

 

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.