【问题标题】:Integrate Gamecenter in cocos2d game在 cocos2d 游戏中集成 Gamecenter
【发布时间】:2011-06-08 11:34:46
【问题描述】:

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

【问题讨论】:

    标签: cocos2d-iphone game-center


    【解决方案1】:

    更新:

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


    您好,我建议您使用 Steffen Itterheim 的 GKHelper 课程!我为你上传了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;
    

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

    //2.在给定的标头中包含以下委托:

    <GameKitHelperProtocol>
    

    //3.将委托方法添加到 .m

    //4.将 GameKitHelper 添加到“场景”:

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

    //将分数添加到排行榜:

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

    //添加成就完成:

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

    这些是第 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);
    }
    

    【讨论】:

    • 请注意,如果您想将 GameKitHelper 用于多人应用程序,则该类不能充分满足设备在限制应用程序中限制多人游戏的情况设备。
    • 您的 GameKitHelper 无法正常工作。我什至无法在身份验证后立即提交分数,因为每个 [GKLocalPlayer localPlayer] 都会调用 chenging 身份验证状态事件
    • 嗨,就像我在答案中提到的那样,这不是我的助手类,并且已经过时了。不过,我确实创建了自己的一个:github.com/ablfx/ABGameKitHelper
    • 如何禁用 Games Center 中的挑战好友按钮?
    • @Sudhakar 检查你原来问题的答案;)
    【解决方案2】:

    您可以使用 GamKit 框架。游戏中心对于管理您的在线游戏和游戏分数也非常强大。使用游戏中心,您可以创建两种类型的游戏

    1:实时比赛(实时赛车) 2:Turn Base Matchs(在线纸牌游戏)

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

    实时匹配:http://www.raywenderlich.com/3276/game-center-tutorial-for-ios-how-to-make-a-simple-multiplayer-game-part-12

    回合制比赛http://www.raywenderlich.com/5480/beginning-turn-based-gaming-with-ios-5-part-1

    【讨论】:

      【解决方案3】:

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

      window.rootViewController = viewController;

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

      【讨论】:

      • 修改了我的 Helper 类以适用于所有应用程序/iOS 版本
      猜你喜欢
      • 2012-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-20
      • 1970-01-01
      • 2012-07-30
      • 2011-08-12
      相关资源
      最近更新 更多