排行榜

 

1. 准备工作

在使用排行榜功能之前,请确保已完成下列工作:

2. 上传玩家分数

调用reportScore方法上传分数。
参数说明:

  • score : 玩家分数
  • leaderboardId : 要上传分数的排行榜ID
  • scoreTag : 保留字段. 可以传null或空字符串""
  • listener/callback : 上传结果回调

//创建回调
KTLeaderboard.OnReportScoreListener onReportScoreListener = 
new KTLeaderboard.OnReportScoreListener(){

    @Override
    public void onReportScoreResult(boolean isSuccess, 
    String leaderboardId, long score, String scoreTag, KTError error) {
        if(isSuccess){
            //上传成功
        }else{
            //上传失败
        }               
    }
};

//上传分数
KTLeaderboard.reportScore(100, "Your Leaderboard ID", scoreTag, onReportScoreListener);

 [KTLeaderboard reportScore:1000 leaderboardId:@"Your Leaderboard ID"  success:^{
    //上传成功
  } failure:^(NSError *error) {
    //上传失败
}];

static void reportScoreCallback(bool isSuccess,const char *leaderboardId,long long score, char *scoreTag, KTErrorC *error)
{
    if (isSuccess) {
        //上传成功
    } else {
        //上传失败
    }
}


//上传分数
KTLeaderboardC::reportScore(100010, "Your Leaderboard ID", "scoreTag", reportScoreCallback);

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;
    }
}
//上传分数
KTLeaderboard.ReportScore(20000, "Your Leaderboard ID", "scoreTag", this,this.onLeaderboard);

 

还有其它问题?提交请求

0 评论

登录写评论。