Implementing a Game Center button in your Corona SDK Game.
I’ve been trying to figure out how to do a Game Center button for my game and be able to link to the Game Center leaderboards and achievements directly from my Corona SDK based game.
I had not found much information on the Internet on how to do this. Most examples were involving Objective C using Xcode and adding the Game Center framework to the game, then calling relevant methods from the framework.
I basically gave up on the idea about connecting directly to the leaderboards and decided to just try and launch the Game Center app from my game.
Here is the code I used (mostly lifted from Jayant C Varma’s “rating.lua” file found on the Corona SDK site):
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
local function testNetworkConnection() local netConn = require('socket').connect('www.apple.com', 80) if netConn == nil then return false end netConn:close() return true end local function gotoGameCenter() local device = system.getInfo ( "environment" ) local appURL = "gamecenter:" if device == "simulator" then print ( "Cannot spawn this URL in the simulator" ) else if testNetworkConnection() then system.openURL ( appURL ) end end end local gameCenterButton = ui.newButton{defaultSrc="gamecenterbtn.png", defaultX = 164, defaultY = 32, onRelease=gotoGameCenter} gameCenterButton.x = display.contentWidth / 2 gameCenterButton.y = 110 highScores:insert(gameCenterButton) |
And much to my surprise, it works like a charm. Now to track down those pesky specific URL’s…. I should note, this is a new addition to my game and it has not been submitted to Apple yet. No warranties expressed or implied.


Well done. I knew something like this had to exist. Just added it to my game; thanks for the research. Side note…I’ve continued researching now, but can’t find any other URLs with the gamecenter: scheme. Perhaps that’s all there is?
Hey dude that’s awesome! Didn’t find any info on it before, thank you very much!
A little question on this… do you know if there’s any possible way to update gamecenter achievements without having to deal with openfeint first? My users are starving for that! :-S
Not that I’m aware of. Many of us would like Ansca to give us just Game Center support, but I suspect they have a lot of higher priority items, including all the iOS 5.0 goodies to implement and since we get Game Center for free with OF, I expect its lower on the list.
Hi!
What are the news?
Was your game finally accepted with the GC button?
Thanks!
Juanjo
It was accepted, but I never could get OF to talk to GC, so I removed GC support in later versions.
Thanks very much! Worked like a charm.