我对这个问题感到疯狂。只是按照如何使用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
在设备上尝试示例什么都不做,只需登录游戏中心用户......
请帮忙吗?
答案 0 :(得分:0)
在initCallback
中,如果event.data
为false,则表示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
在sim中运行上面的代码并查看控制台;在设备上运行它并查看日志文件。这可能会给出问题的线索。