@animonger On iOS device. Can you check the accuracy of my code.
Code is:
build.settings
settings = {orientation = { default = "portrait", }, plugins = { ["plugin.google.play.services"] = { publisherId = "com.coronalabs", supportedPlatforms = { iphone=true, android=true } }, ["CoronaProvider.gameNetwork.apple"] = { publisherId = "com.coronalabs", supportedPlatforms = { iphone=true } }, }, }
main.lua
local gameNetwork = require( "gameNetwork" )-- local loggedIntoGC = false local function initCallback( event ) if ( event.type == "showSignIn" ) then -- This is an opportunity to pause your game or do other things you might need to do while the Game Center Sign-In controller is up. elseif ( event.data ) then loggedIntoGC = true native.showAlert( "Success!", "", { "OK" } ) end end local function onSystemEvent( event ) if ( event.type == "applicationStart" ) then gameNetwork.init( "gamecenter", initCallback ) return true end end Runtime:addEventListener( "system", onSystemEvent )
restart.lua (this is shown to user when he lost the game, there you can see score, highscore, buttons, one button is reserved for game center)
local gameNetwork = require( "gameNetwork" ) composer.setVariable( "currentScore", 100 ) composer.setVariable( "currentLeaderboardID", "MyIDFromItunesConnect" ) composer.setVariable( "currentLeaderboardTitle", "NameOfLeaderboard" )
function onClickGameCenter() --this function is called when user press the gamecenter button localPlayerScore = { category=composer.getVariable( "currentLeaderboardID" ), value=composer.getVariable( "currentScore" ) }, gameNetwork.show( "leaderboards", { leaderboard={ category=composer.getVariable( "currentLeaderboardID" ) } } ) end