To implement Game Center more easily into Codea, I have created a helper class that simulates the different calls that you would add into Xcode after you export your solution. By doing it this way, now I only have to un-comment the 1 line in AppDelegate.mm and then change 1 boolean to “false” and it works.
I have tested it and it seems to work. Just want to make sure someone else does not see an problems with it.
-- Simulates the use of Game Center, so you can actually write the calls in Codea and still test on the iPad
if (DEBUG_GAMECENTER == true) then
function GameCenterClass()
-- the new instance
local self = {
}
function self.enabled()
-- simulates that Game Center is logged in
return true
end
function self.showLeaderboards(leaderboardID)
-- Show leaderboards
if (leaderboardID == nil) then
alert("Game Center leaderboard screen will pop up.", "Game Center Simulation")
else
alert("Game Center leaderboard with ID " .. leaderboardID .. " will pop up.", "Game Center Simulation")
end
end
function self.showAchievements()
-- Show achievements
alert("Game Center achievement screen will pop up.", "Game Center Simulation")
end
function self.submitScore(score, leaderboardID)
-- simulates submitting a score to Game Center
if (leaderboardID == nil) then
alert("Default Leaderboard updated with score " .. score, "Game Center Simulation")
else
alert("Leaderboard with ID " .. leaderboardID .. " updated with score " .. score, "Game Center Simulation")
end
end
function self.submitAchievement(achievementID, percent)
-- simulates submitting an achievement to Game Center
alert("Achievement with ID " .. achievementID .. " updated to " .. percent .. "%", "Game Center Simulation")
end
-- return the instance
return self
end
-- create a global instance and call it "gamecenter"
-- the exact name you need to impliment when you make the changes in Xcode
-- but now you can do it locally :)
gamecenter = GameCenterClass()
end