Cocos2d iphone 在cocos2d游戏中集成Gamecenter

Cocos2d iphone 在cocos2d游戏中集成Gamecenter,cocos2d-iphone,game-center,Cocos2d Iphone,Game Center,有谁知道如何将游戏中心集成到Cocos2d中。 请告诉我步骤,以便我可以将其集成到游戏中。更新: 我创建了自己的Helper类,可用于所有类型的应用程序(也可用于CoCo2D 1和2+) 您好,我建议您使用Steffen Itterheim提供的GKHelper类!我为您上传了gkheloper.h/gkheloper.m: 然后按照以下说明操作: //0.0将GameKit框架添加到项目中(如果您不知道如何执行此操作,请询问;) //0。将AppDelegate.m中的“[window a

有谁知道如何将游戏中心集成到Cocos2d中。
请告诉我步骤,以便我可以将其集成到游戏中。

更新:

我创建了自己的Helper类,可用于所有类型的应用程序(也可用于CoCo2D 1和2+)


您好,我建议您使用Steffen Itterheim提供的GKHelper类!我为您上传了gkheloper.h/gkheloper.m:

然后按照以下说明操作:

//0.0将GameKit框架添加到项目中(如果您不知道如何执行此操作,请询问;)

//0。将AppDelegate.m中的“[window addSubview:viewController.view];”更改为: //如果您使用的是0.99.5之后的任何cocos2D版本,请执行此操作:

window.rootViewController = viewController;
//一,。将Gamekithelper.h/.m添加到项目中

//二,。在给定标题中包含以下委托:

<GameKitHelperProtocol>
//将分数添加到排行榜:

GameKitHelper *gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper submitScore:scoreValue category:@"LeaderboardID"];
//添加成就完成:

GameKitHelper *gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper reportAchievementWithID:@"AchievementID" percentComplete:100];
以下是第3步中提到的需要添加的委托方法:


虽然Alexander Blunck的回答是合理的,但对于iOS的早期版本(如3.2),下面这行代码会出错,这不是您想要的

window.rootViewController=视图控制器


如果您打算使用Steffen的代码(ugh),那么您可能希望添加一个方法来直接设置ui视图控制器,而不是让它假设可以通过UIApplication获取它。

您可以使用GamKit framework。游戏中心是非常强大的管理您的在线游戏和游戏分数以及。有了游戏中心,您可以创建两种类型的游戏

1:实时比赛(实时赛车) 2:回合基础赛(在线纸牌游戏)

我正在与您分享RaywenderLich的链接:

实时匹配:


基于回合的比赛

请注意,如果您想将GameKitHelper用于多玩家应用程序,则该类无法充分满足设备上限制应用程序限制多玩家游戏的情况。您的GameKitHelper无法正常工作。我甚至不能在身份验证后立即提交分数,因为chenging authentication state事件是在每个[GKLocalPlayer]Hi上调用的,正如我在回答中提到的,这不是我的助手类,已经过时了。不过,我确实创建了一个自己的游戏:如何禁用Games Center中的“挑战朋友”按钮?@Sudhakar检查原始问题的答案;)修改了my Helper类以与所有应用程序/iOS版本一起使用
GameKitHelper *gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper reportAchievementWithID:@"AchievementID" percentComplete:100];
#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);
}