Corona SDK的游戏网络(gameNetwork)和Game Center在iOS上无法正常工作。

我对这个问题感到很疯狂。按照如何使用gameNetwork的指南,却没有成功。这是我的代码:

main.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

在设备上尝试示例没有任何作用,只是登录游戏中心用户...

请帮忙,谢谢!

点赞
用户869951
用户869951

在你的 initCallback 中,如果 event.datafalse,这意味着 gameNetwork 无法登录到服务器,因此请求分数将失败。你应该检查错误:

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

在模拟器中运行上面的代码,并查看控制台;在设备上运行并查看日志文件。这很可能会给出问题的线索。

2014-04-06 02:43:12