cocos2d-x lua游戏开发笔记

排行榜lua代码内封装方便调用

2019-01-28  本文已影响0人  Zi_Fi
function bridge.loginGameCenter()
    if gt.isIOSPlatform() then
        gt.luaBridge.callStaticMethod("GameCenterController","loginGameCenter",nil)
    elseif gt.isAndroidPlatform() then
        local className = "com/zzg/FreshChopping/AppActivity"
        gt.luaBridge.callStaticMethod(className,"loginGameCenter",nil)
     end
end 
-- 初始化分数
function bridge.getScoreData()
    if gt.isIOSPlatform() then
        local args = {id = "123456"}
        gt.luaBridge.callStaticMethod("GameCenterController","getScoreData",args)
    elseif gt.isAndroidPlatform() then
        local className = "com/zzg/FreshChopping/AppActivity"
        local args = {gt.android_leaderboard_id}
        gt.luaBridge.callStaticMethod(className,"getScoreData",args)
     end
end

-- 上传游戏中心最高分
function bridge.upLoadScore(score)
    if gt.isIOSPlatform() then
        local args = {id = "20181115",score=tostring(score)}
        gt.luaBridge.callStaticMethod("GameCenterController","uploadScore",args)
    elseif gt.isAndroidPlatform() then
        print("upLoadScore = "..score)
        gt.log("upLoadScore = ",score)
        local className = "com/zzg/FreshChopping/AppActivity"
        local args = {gt.android_leaderboard_id,score}
        local sigs = "(Ljava/lang/String;I)V" 
        gt.luaBridge.callStaticMethod(className,"uploadScore",args,sigs)
    end
end

-- 获取游戏中心的最高分
function bridge.getGameCenterScore()
    if gt.isIOSPlatform() then
        local ok,ret = gt.luaBridge.callStaticMethod("GameCenterController","getScore",nil)

        return ret or 0
    elseif gt.isAndroidPlatform() then
        local className = "com/zzg/FreshChopping/AppActivity"
        local sigs = "()I"
        local ok,ret = gt.luaBridge.callStaticMethod(className,"getScore",nil,sigs)
        print("getScore = "..ret)
        gt.log("getScore = ",ret)
        return ret or 0
    end
end

-- 展示排行榜
function bridge.showLeaderboard()
    if gt.isIOSPlatform() then
        local args = {id = "20181115"}
        gt.luaBridge.callStaticMethod("GameCenterController","showLeaderboard",args)
    elseif gt.isAndroidPlatform() then
        local className = "com/zzg/FreshChopping/AppActivity"
        local args = {gt.android_leaderboard_id}
        gt.luaBridge.callStaticMethod(className,"showLeaderboard",args)
    end
end
上一篇 下一篇

猜你喜欢

热点阅读