Viv*_*012 10 cocos2d-iphone game-center
有谁知道如何在Cocos2d中集成游戏中心.请告诉我步骤,以便我可以将其整合到我的游戏中.
Ale*_*nck 30
更新:
我创建了自己的帮助程序类,适用于所有类型的应用程序(也是Cocos2D 1和2+) https://github.com/alexblunck/ABGameKitHelper
嗨,我建议您使用Steffen Itterheim的GKHelper Class!我为你上传了GKHelper.h/GKHelper.m:http://www.cl.ly/7ReW
然后按照以下说明操作
//0.0将GameKit框架添加到项目中(询问您是否知道如何执行此操作;))
// 0.更改"[window addSubview:viewController.view];" 在AppDelegate.m中://如果您在0.99.5之后使用任何cocos2D版本,请执行此操作:
window.rootViewController = viewController;
Run Code Online (Sandbox Code Playgroud)
// 1.将Gamekithelper.h/.m添加到项目中
// 2.在给定标题中包含以下委托:
<GameKitHelperProtocol>
Run Code Online (Sandbox Code Playgroud)
// 3.将委托方法添加到.m
// 4.将GameKitHelper添加到"场景":
GameKitHelper *gkHelper = [GameKitHelper sharedGameKitHelper];
gkHelper.delegate = self;
[gkHelper authenticateLocalPlayer];
Run Code Online (Sandbox Code Playgroud)
//为排行榜添加分数:
GameKitHelper *gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper submitScore:scoreValue category:@"LeaderboardID"];
Run Code Online (Sandbox Code Playgroud)
//添加成就完成:
GameKitHelper *gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper reportAchievementWithID:@"AchievementID" percentComplete:100];
Run Code Online (Sandbox Code Playgroud)
这些是在步骤3中提到的需要添加的委托方法:
#pragma mark GameKitHelper delegate methods
-(void) onLocalPlayerAuthenticationChanged
{
GKLocalPlayer* localPlayer = [GKLocalPlayer localPlayer];
CCLOG(@"LocalPlayer isAuthenticated changed to: %@", localPlayer.authenticated ? @"YES" : @"NO");
if (localPlayer.authenticated)
{
GameKitHelper* gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper getLocalPlayerFriends];
//[gkHelper resetAchievements];
}
}
-(void) onFriendListReceived:(NSArray*)friends
{
CCLOG(@"onFriendListReceived: %@", [friends description]);
GameKitHelper* gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper getPlayerInfo:friends];
}
-(void) onPlayerInfoReceived:(NSArray*)players
{
CCLOG(@"onPlayerInfoReceived: %@", [players description]);
}
-(void) onScoresSubmitted:(bool)success
{
CCLOG(@"onScoresSubmitted: %@", success ? @"YES" : @"NO");
}
-(void) onScoresReceived:(NSArray*)scores
{
CCLOG(@"onScoresReceived: %@", [scores description]);
GameKitHelper* gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper showAchievements];
}
-(void) onAchievementReported:(GKAchievement*)achievement
{
CCLOG(@"onAchievementReported: %@", achievement);
}
-(void) onAchievementsLoaded:(NSDictionary*)achievements
{
CCLOG(@"onLocalPlayerAchievementsLoaded: %@", [achievements description]);
}
-(void) onResetAchievements:(bool)success
{
CCLOG(@"onResetAchievements: %@", success ? @"YES" : @"NO");
}
-(void) onLeaderboardViewDismissed
{
CCLOG(@"onLeaderboardViewDismissed");
GameKitHelper* gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper retrieveTopTenAllTimeGlobalScores];
}
-(void) onAchievementsViewDismissed
{
CCLOG(@"onAchievementsViewDismissed");
}
-(void) onReceivedMatchmakingActivity:(NSInteger)activity
{
CCLOG(@"receivedMatchmakingActivity: %i", activity);
}
-(void) onMatchFound:(GKMatch*)match
{
CCLOG(@"onMatchFound: %@", match);
}
-(void) onPlayersAddedToMatch:(bool)success
{
CCLOG(@"onPlayersAddedToMatch: %@", success ? @"YES" : @"NO");
}
-(void) onMatchmakingViewDismissed
{
CCLOG(@"onMatchmakingViewDismissed");
}
-(void) onMatchmakingViewError
{
CCLOG(@"onMatchmakingViewError");
}
-(void) onPlayerConnected:(NSString*)playerID
{
CCLOG(@"onPlayerConnected: %@", playerID);
}
-(void) onPlayerDisconnected:(NSString*)playerID
{
CCLOG(@"onPlayerDisconnected: %@", playerID);
}
-(void) onStartMatch
{
CCLOG(@"onStartMatch");
}
-(void) onReceivedData:(NSData*)data fromPlayer:(NSString*)playerID
{
CCLOG(@"onReceivedData: %@ fromPlayer: %@", data, playerID);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11754 次 |
| 最近记录: |