int GameCenterInit(void(*callback)(int type, int flag, int value, char *desc));
Authenticates the local user and initializes Game Center.
Return Value
Returns one if successful. Be sure to use the global Game Center callback specified in GameCenterInit() to get results from the Game Center servers.
If Game Center is unsupported on the device this function returns zero.
Parameters
callback Specifies a global event handler to receive feedback from the Game Center server.
Parameters passed to the callback are:
type Specifies which type of message is being sent back to the client. Types passed are as follows:
flag Specifies whether the callback is reporting an error. 0 = false; 1 = true.
value Specifies the value being reported back to the client. Varies, depending on the type of reply.
If flag = 1, then the error code can be one of the following values:
desc Contains a string description relating to the event. Applies to Achievement Post, Score Post and Leaderboard Rank events. For Achievement Post events, the name of the updated achievement is passed, for Score Post and Leaderboard Rank events, the name of the leaderboard is passed. The maximum length of the value in this parameter is 100 bytes.
Remarks
GameCenterInit() initializes the Game Center feature in your application. In order to use Game Center features, you will need an Apple Developer account with an application defined, and Game Center enabled for your application. Additionally, you will want to set up at least one leaderboard and / or achievement for your game.
You should call GameCenterInit() early in the execution of your application.
See iTunes Connect for more information on configuring your application for Game Center.
Availability
Available in DragonFireSDK 2.0 and later.
Example
#include "DragonFireSDK.h"
const char *ErrorNoError(int value) { if (value) return("ERROR! "); return(""); }
void OnGameCenter(int type,int flag,int value,char *desc) { switch (type) { case 1: // Authentication printf("Authentication event result: %svalue:%d desc:%s\n",ErrorNoError(flag),value,desc); break; case 2: // Achievements Post printf("Achievements Post event result: %svalue:%d desc:%s\n",ErrorNoError(flag),value,desc); break; case 3: // Achievements Reset printf("Achievements Reset event result: %svalue:%d desc:%s\n",ErrorNoError(flag),value,desc); break; case 4: // Score Post printf("Score Post event result: %svalue:%d desc:%s\n",ErrorNoError(flag),value,desc); break; case 5: // Leaderboard Rank printf("Leaderboard Rank event result: %svalue:%d desc:%s\n",ErrorNoError(flag),value,desc); break; } }
int OnButton(int id) { switch (id) { case 1: GameCenterAchievementsShow(); break; case 2: GameCenterLeaderboardShow(); break; case 3: GameCenterAchievementsPost("com.mycompany.myapp.myachievement", 100.0f); break; case 4: GameCenterAchievementsReset(); break; case 5: GameCenterLeaderboardPostScore("com.mycompany.myapp.myleaderboard", 100); break; case 6: GameCenterGetLeaderboardRank("com.mycompany.myapp.myleaderboard"); }
return(id); }
void AppMain() { GameCenterInit(OnGameCenter);
ButtonAdd("Images/Button", 10, 10, OnButton, 1); ButtonAdd("Images/Button", 10, 50, OnButton, 2); ButtonAdd("Images/Button", 10, 90, OnButton, 3); ButtonAdd("Images/Button", 10, 130, OnButton, 4); ButtonAdd("Images/Button", 10, 170, OnButton, 5); ButtonAdd("Images/Button", 10, 210, OnButton, 6); }
void AppExit() {
}
void OnTimer() {
} |