在cocos2d游戏中集成Gamecenter [英] Integrate Gamecenter in cocos2d game

查看:102
本文介绍了在cocos2d游戏中集成Gamecenter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道如何整合游戏中心在Cocos2d。
请告诉我步骤,以便我可以在我的游戏中整合。

Is there any one who knows how to integrate game center in Cocos2d. Please tell me steps so i can integrate that in my Game.

推荐答案

>

UPDATE:

我创建了我自己的Helper类,适用于所有类型的应用程序(也是Cocos2D 1& 2+)
https://github.com/alexblunck/ABGameKitHelper

I created my own Helper Class that works with all kind of Apps (also Cocos2D 1 & 2+) https://github.com/alexblunck/ABGameKitHelper

您好,我建议您使用Steffen Itterheim的GKHelper Class!我为您上传了GKHelper.h / GKHelper.m: http://www.cl.ly/7ReW

Hi I suggest you use GKHelper Class from Steffen Itterheim! I uploaded the GKHelper.h / GKHelper.m for you: http://www.cl.ly/7ReW

然后按照以下说明:

// 0.0将GameKit框架添加到项目t知道如何做到这一点)))

//0.0 Add GameKit Framework to Project (Ask If you don't know how to do this ;) )

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

//0. Change "[window addSubview: viewController.view];" in the AppDelegate.m to: //Do this if you're using any release of cocos2D after 0.99.5:

window.rootViewController = viewController;

// 1。将Gamekithelper.h / .m添加到项目

//1. Add Gamekithelper.h / .m to project

// 2。在给定的标题中包含以下代理:

//2. Include following delegate in given header:

<GameKitHelperProtocol>

// 3。将代理方法添加到.m

//3. Add Delegate Methods to .m

// 4。将GameKitHelper添加到Scene:

//4. Add GameKitHelper to "Scene":

GameKitHelper *gkHelper = [GameKitHelper sharedGameKitHelper];
gkHelper.delegate = self;
[gkHelper authenticateLocalPlayer];

//将分数加到排行榜:

//Adding score to leaderboard:

GameKitHelper *gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper submitScore:scoreValue category:@"LeaderboardID"];

//添加成就完成

GameKitHelper *gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper reportAchievementWithID:@"AchievementID" percentComplete:100];

这些是需要在步骤#3中提到的委托方法:

These are the delegate Methods that need to be added mentioned in Step #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);
}

这篇关于在cocos2d游戏中集成Gamecenter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆