科罗纳 SDK - 游戏网络 + 游戏中心 iOS 无法正常工作



我对这个问题很生气。只是遵循如何使用游戏网络的指南,但没有成功。这是我的代码:

主.lua

gameNetwork = require "gameNetwork"
loggedIntoGC = false

local function initCallback( event )
if event.data then
    loggedIntoGC = true
    -- native.showAlert( "Success!", "User has logged into Game Center", { "OK" } )
else
    loggedIntoGC = false
    gameNetwork.request( "loadScores", 
        { leaderboard={ category="com.mycompany.mygame.myrankingid", 
        playerScope="Global", timeScope="AllTime", range={1,50} },
        listener=requestCallback } )
    -- native.showAlert( "Fail", "User is not logged into Game Center", { "OK" } )
end
end
-- function to listen for system events
local function onSystemEvent( event ) 
if event.type == "applicationStart" then
    gameNetwork.init( "gamecenter", initCallback )
    return true
end
end
Runtime:addEventListener( "system", onSystemEvent )

然后只是为了测试:

if loggedIntoGC then 
gameNetwork.request( "setHighScore", 
  { localPlayerScore={ category="com.mycompany.mygame.myrankingid", value=t.text }, 
  listener=requestCallback } ); 
end
if loggedIntoGC then 
gameNetwork.request( "loadScores", 
  { leaderboard={ category="com.mycompany.mygame.myrankingid", playerScope="Global", timeScope="AllTime", range={1,50} }, 
  listener=requestCallback } ); 
end
if loggedIntoGC then 
gameNetwork.show( "leaderboards", 
  { leaderboard={ category="com.mycompany.mygame.myrankingid", timeScope="AllTime" } }     ); 
end

在设备上尝试示例什么都不做,只是登录游戏中心用户...

有什么帮助吗?

在你的initCallback中,如果event.data为假,这意味着游戏网络无法登录服务器,因此请求分数将失败。您应该检查错误:

local function scoresCallback(event)
    print("Got " .. #event.data .. " scores")
    print("Local player score: " .. event.localPlayerScore)
end
local function initCallback( event )
    if event.data then
        loggedIntoGC = true
        print('Successful login')
        gameNetwork.request( "loadScores", 
        { 
            leaderboard = { 
                category = "com.mycompany.mygame.myrankingid", 
                playerScope = "Global", 
                timeScope = "AllTime", 
                range={1,50} 
            },
            listener = scoresCallback,
        } )
    else
        loggedIntoGC = false
        print("Error init game center: ", event.errorMessage)
    end
end

sim中运行上面的代码并查看控制台;在设备上运行它并查看日志文件。这可能会为问题提供线索。

最新更新