如何在玩游戏老是自动关闭时关闭Game Center

查看: 17767|回复: 28
[已解决]谁能告诉我这该死的GAME CENTER如何注销!!
第一个问题,不知道为什么我这个GC无法注销。在设置里注销完,切换回来,用户还是显示登陆状态,不管我是开启飞行模式还是关闭网络连接,总是显示登陆状态。种性强韧!你这头刚在设置里注销成功,切换进GAME CENTER就发现还是登录状态,切换回设置一看能气死人。即便不切出设置,注销完换个选项再回来,肯定还是坚挺。我勒个去,种性强韧!!
第二个问题,以前我的苹果ID是用雅虎中国邮箱注册的,去年被迫改换其他邮箱,在苹果官网完成ID邮箱更新后,iCloud、iTunes、App Store的账户邮箱都随着更新,妥妥的。唯独这个GAME CENTER,经常莫名其妙给我恢复成以前的雅虎中国邮箱,尤其是在非正常退出游戏时更是如此。种性强韧!!!更可气的是,自动变成旧的ID邮箱后,这GAME CENTER居然TMD还是登录状态!而这时其他需要苹果ID的比如iTunes、iCloud什么的还都是规规矩矩的更新后的邮箱。种性强韧!!!!
哪位朋友能给解决吗,先谢了。
我也是 注销就又自动了....
&&&本楼为最佳答案&&&
这个其实好办,你给你的Apple ID换个密码,然后你再打开任何游戏,或者Game Center后,会提示你重新登录,ok,拒绝登录,这样就搞定了。
发自爱谱社区手机版
ahui 发表于
这个其实好办,你给你的Apple ID换个密码,然后你再打开任何游戏,或者Game Center后,会提示你重新登录,o ...
嘿嘿 me too
楼上这个思路很好。以前别人在我手机上登陆ins,哪怕我注销了删掉app重装然后登陆我自己的ins账号,还是会收到他的ins消息推送,烦死了。
后来逼他改了密码,我的世界就清净了。。。。
退出GameCenter之后 重启一下, 别的机器也有登陆的就都退出来.
不玩游戏了。。
改密码!!!!!
发自爱谱社区手机版
楼上各位,美区ID敢随便改密码?
重来没想过要注销
发自爱谱社区手机版
zuiaiqie 发表于
楼上这个思路很好。以前别人在我手机上登陆ins,哪怕我注销了删掉app重装然后登陆我自己的ins账号,还是会 ...
Ins? Instagram吗?
这个其实好办,你给你的Apple ID换个密码,然后你再打开任何游戏,或者Game Center后,会提示你重新登录,o ...
不行,我按这个办法试了,根本就没提示我需要重新输入密码登陆,进入游戏或GAME CENTER依旧显示我的信息。
更可恨的是,我尝试注销后,直接用另一个ID(比如外国的某一个)登陆,然后进入GAME CENTER看,是改过来了,GAME CENTER好友列表为空,进入游戏后,MD那些好友还在!退出来再进入设置注销这个外国ID,不登陆任何ID,再进游戏,我去,那些主ID的好友们都在那里等着我呢!!!退出游戏进设置里看,NND,这时候显示在我的GAME CENTER里的ID邮箱居然是那个早被废弃的雅虎中国邮箱,而且还是登陆状态!!!!这也就是我主题里说的第二个问题,真TMD种性强韧。
我快要疯掉了.........
楼上其他好友提到的重启系统什么的,我在提问前都试过了。
发自爱谱社区手机版
本帖最后由 shanatama 于
20:20 编辑
远方逍客 发表于
楼上各位,美区ID敢随便改密码?
内个我改了好几次了,不过我的账户本来就有些部分被美国那里认为有问题,就是有的游戏内购会说我无法买,得联系苹果客服,客服说我信息个人信息违反了什么,处于非正常状态,不过也就这么一个游戏内购我不能正常支付,其他app或者内购我用美国Id付钱都没什么问题,即使我改了很多密码,你这里有啥心得分享下吗
内个我改了好几次了,不过我的账户本来就有些部分被美国那里认为有问题,就是有的游戏内购会说我无法买, ...
这个没啥心得啊,美区ID自从申请了就没改过密码,之前在水区看到有人说改密码or换邮箱可能会被办,所以一直没试过修改,使用中一直也没有问题就更不能蛋疼的去测试了
这个没啥心得啊,美区ID自从申请了就没改过密码,之前在水区看到有人说改密码or换邮箱可能会被办,所以一 ...
嗯,我觉得我的问题就是改过地址了
彻底放弃尝试了。
估计最终得在全部初始化设置、砸烂现在的设备重新购置新的、放弃现在的ID另起炉灶、彻底放弃苹果产品之中择其一才能根本解决问题。
不行,我按这个办法试了,根本就没提示我需要重新输入密码登陆,进入游戏或GAME CENTER依旧显示我的信息 ...
其实还有最后一个办法,直接写信给苹果客服,求助客服帮你解决问题。
楼上各位,美区ID敢随便改密码?
我去年年底的时候还是纯英文字母密码呐,08年到现在都没改过。后来借人装sleepcycle,装完了不给我注销,用我账号下那些脑残游戏,忍无可忍改密码了。。。
开发者中心 -
帮助中心 -
网站地图 -
爱应用 - http://www.iapps.im传谷歌拟复制苹果iOS游戏平台Game Center
科技讯 5月10日消息,据国外媒体报道,据一匿名知情消息人士透露,正开发一款类似于专为游戏玩家设计的社交网络平台Game Center的应用,同时还将改进 Play的支付系统,简化应用购买流程。消息人士透露,谷歌正准备推出一款功能类似于苹果的Game Center。Game Center可将iOS App Store应用商店上所有游戏的玩家连接在一块。谷歌显然是意识到移动游戏的重要性,正寻求提供诸如OpenFeint的第三方服务的替代选择。苹果Game Center通过提供奖励提高游戏黏性,使得单人游戏更加社交化。与之一样,谷歌尚未公布的应用也将通过增加一个含有奖杯和网络排行榜的成就体系,为Android游戏添加社交元素。据说该款应用将包含与朋友竞争的选项,不过还不能确定此举是否将奏效。
谷歌另一个据传也在研发当中的项目是Google Play的简化。据悉,该公司正致力于修改Google Play的支付系统,使其简洁性能与iOS App Store相媲美。Google Play缺少苹果基于iTunes的系统,该系统自2008年连同iPhone 3G一起推出后已成为行业标准。消息人士并没详细透露Google Play在做哪些变动,以及变动的具体实施时间。谷歌尚未正式公布任何与上述传闻中的应用相关的信息,且对是否将改造Google Play的支付系统三缄其口。(乐邦)
(本文来源:网易科技报道
跟贴读取中...
跟贴昵称修改后,论坛昵称也会变哦
复制成功,按CTRL+V发送给好友、论坛或博客。
浏览器限制,请复制链接和标题给好友、论坛或博客。
网易科技48小时评论排行
评论1864条
评论1576条
评论1415条
评论1270条
评论1017条
网易公司版权所有查看: 33819|回复: 40
《无尽之剑2》V 9608.5 无限金币版 【注意】首次先关闭GameCenter和iCloud增8亿金币
《无尽之剑2》v9608.5:3D剑术战争动作游戏,延续一代故事,全新战斗方式。
【【注意】首次先关闭GameCenter和iCloud增8亿金币】
=本存档支持正版,无需=
存档下载:
希望大家支持,小弟会不断努力发更多存档,对大家有帮助的话希望大家回个帖加点分,小弟在这谢谢了
游戏介绍:
《无尽之剑 II》由Epic Games旗下屡获嘉奖的工作室ChAIR Entertainment出品,是专门为iPhone、iPod Touch和iPad平台打造的最卖座剑术战争动作游戏的《无尽之剑》的续篇。
《无尽之剑 II》使用Epic顶级的虚幻引擎3技术制作,在这个美轮美奂的3D世界中拥有令人惊叹的视觉效果、全新的战斗方式以及高级角色定制功能,这些更是将手持移动平台的游戏质量提升至一个新的高度。
无尽之剑的成功故事将会继续完美演绎!
不死之王被打败,不可思议的英雄出现了,您现在必须去探索隐藏在无尽之剑秘密背后的真相。当您进一步深入探索这个到处是具有不死之身的敌手及其同盟军泰坦的世界时,年轻赛里斯的神奇旅程将会由此继续展开。您能够在这场跨越时间长河的勇士与恶棍之间的剑术战斗冒险中,揭开所有未解之谜并驾驭无尽之剑的神奇力量吗?
强大&动态的3D世界:
探索绚丽广阔的游戏场景,在您通往具有异国情调的地点的远行和探险过程中场景会不断地发生动态变换,例如,以东方为主题的塞得海故居或者是由欧洲中世纪萌发灵感的血泪之穴,它们都可以通过多个路径去探索。
具有3种全新的战斗方式:
现在您可以从多个武器、盔甲和法术类中进行选择,其中每个都具有专门的功能,例如,双持武器, 双手武器 以及标准的武器&盾牌类。通过无尽之剑II直观的“瞬间上手”的玩法,你可以体验多种不同风格的战斗套路。虽然上手很容易,但要成为高手可需要磨练哦!
无尽之剑的品牌角色定制功能改进:
使用您在探索途中发现并收集的神秘物质创建和锻造更加强大的武器,通过全新的元素力量&功能全面扩充您的军火库!
前世之谜揭晓:
随着游戏进展您被带入到神秘的不死战士塞得海的王国,由此进一步了解无尽之剑那充满传奇色彩的故事情节,并会发现有关神秘工匠的真相以及他所拥有的力量。
由虚幻技术提供的最新iOS功能:
移动设备平台游戏中的写实视觉效果体验,附带全新的iCloud支持和HDMI高清输出功能。
App广泛性 - 只要支付很少的费用就可以在iPhone 3GS、iPhone 4、iPhone 4S、iPad、iPad 2、iPod Touch 3(16 GB及以上)或iPod Touch 4上玩《无尽之剑》。
针对iPhone 4S和iPad 2进行了优化 – 包括采用了iPhone 4S和iPad 2的增强型视觉效果功能的高分辨率图形和光照。
推荐:游戏之前请将设备更新至最新的iOS版本。
存档下载:
使用方法:
1.&&并安装此应用
2.&&运行压缩包内的”存档安装器.exe“文件
3.&&连接设备并点击安装存档
4.&&点击继续,存档安装成功
看帖回帖是美德!!!求加分求回帖!
太厉害了&&! 兄弟!我太喜欢!&&简直就是我心目中的女神!
楼主,我怎么装不起啊,试了很多次。。求解
怎么关闭GameCenter和iCloud
{118}没资源哦。
看看咯!谢谢楼主!
错误:数据丢失
(20.59 KB, 下载次数: 56)
00:06 上传
这个给力,感谢分享
怎么关闭GameCenter和iCloud ?安装了金币不增加啊
会覆盖原来的存档吗?
Powered by
北京市公安局海淀分局网监中心备案编号:利用iOS的Game Center开发简单多人游戏 教程: Part 1/2 - 推酷
利用iOS的Game Center开发简单多人游戏 教程: Part 1/2
(原文地址:
前面3段是作者写这个主题的缘由,不过具体翻译了)
该系列分为2部分,我们将通过Cocos2D和Game Center做一个简单的2人对战的网络游戏。
示例游戏实现机制很简单。实例是一个小狗和小猫的竞赛游戏,玩家频率越高,越容易获取游戏胜利。
本教程需要对Cocos2D有一个基本的了解。如果不熟悉Cocos2D, 推荐先了解一下Cocos2D的基本知识,这里是教程
完全实现本教程,需要注册一个iOS的开发帐号,把该应用对应d的Game Center机能打开.另外还需要一个物理设备(这样就可以在模拟器上运行该应用,另外一个运行在设备上,进行通信测试).
准备好了? &让我们开始GO!
教程的该部分主要描述游戏玩家匹配和多玩家对战机能的实现。
游戏的逻辑部分不是咱们该章节的重点,作者很热心的提供了逻辑部分的完整代码(&
),该部分不包含网络连接部分代码。
下载代码,运行该工程,运行效果如下图所示:
本游戏不复杂,而且注释也很详细, 看一下代码,并确认把代码的部分都整明白了。
如果大家感兴趣,原作者有兴趣做一个分离的章节,讲述怎么从头实现该部分游戏,大家如果喜欢可以到论坛
投票,申请作者写该部分。
打开Game Center: 概述
截至到目前,我们已经有了一个可以正常可玩得游戏,除了有些无聊,都是自己一个人来玩。
通过Game Center, 对战会增添不少乐趣。 即可以邀请朋友一起玩,也可以随机选择在线的玩家一起玩。
在开始写任何Game Center代码前, 还需要作一下下面的事情:
创建并设定App ID
在iTunes Connect中进行注册
让咱们一起按照顺序把上面的步骤把准备工作做完.
创建并设定App ID
第一步创建和设定App ID。做这一步,需要先登录iOS Dev &Center, 在 iOS Provisioning Portal地方进行添加。
选择 App IDS标签,新建一个App ID(Bundle identifier地方,根据需要进行设定)
最重要的部分是Bundle Identifer部分。你需要设定一个不重复的字串(不要设定成和作者开发的一样,否则会冲突的)。 大家约定俗成用一个反转的域名来设定一个唯一的字串,来避免冲突。
上面的步骤完成后,点击Sumbti,提交。打开Cat Race Xcode project工程文件, 选择Resources\Info.plist文件, 把Bundle identifier设定成刚才上一步设定的那个app id, 大体如下图所示(Bundle identifier地方设定成刚才自己追加的那个):
最后要注意的事情. Xcode有时会有一些让人烦得问题,当修改完bundle identifier后, 检查一下下列的事情:
删除原来id的Cat Race的应用,不管是模拟器还是设备上的
关闭退出模拟器,如果模拟器打开的话
在xCode中Product菜单地方,选择 Clean
恭喜—现在有了一个自己应用的App ID并且你的应用正在使用该App ID。接下来,需要登记一下该应用并打开enable Game Center.
在iTunes Connect中进行注册
接下来是登陆&iTunes Connect&,给该应用创建一个实体条目.
登陆iTunes Connect, 选择管理应用,点击“Add New App”,进行注册登记
在进行注册登记的第一个画面,输入App Name和SKU Number,选择刚才创建的App ID.
点击继续,按照提示设定一下其他的应用的基本信息.
不要太介意应用的信息是否确切,后面还可以进行调整。
当上面的事情都做完后,点击Save, 如果必要的信息设定都没有问题的话,会出现”Prepare for upload”的状态信息显示。如下图所示
点击右上的蓝色按钮,点击蓝色的“Enable” 按钮, 点击 “Done”完成操作. 这样就把你App的Game Center给打开了,让我开始写一些代码吧!
顺便说一下,在 “Manage Game Center”页面部分, 大家可能也注意到了Leaderboards(排行榜)和Achievments(成就)2个功能选项.
该教程中将不涉及排行榜和成就功能,如果大家感兴趣的话, 作者有兴趣把这个功能的用例整理到将出版的
验证本地用户:策略
当游戏开始运行,我们要做的第一件事就是去认证本地用户,也就是当前用户.
我们也可以把这个认为是一个 “用户登录Game Center.”的过程。如果用户已经登录了的话,会出现“Welcome back!” ,否则,他将询问玩家的用户名和密码.
认证本地用户不麻烦 – 只需要调用authenticateWithCompletionHandler即可. 一旦用户通过认证,可以任意的把该信息传递到其他任何代码块中.
不过还是有另外一个小窍门。另一种认证方式,用户去log in (or log out!) (—游戏中,该类型偏少,大部分是通过自动认证方式). 玩家可以通过你的应用切换到Game Center app, 登录或者退出,接着切换回游戏应用.
我们的引用需要知道什么时候认证信息发生了变化. 在“authentication changed”Notification提醒中来接收这些信息。
那么, 我们认证玩家的策略如下:
创建一个单独的对象来保管和出来所有的Game Center相关的代码
当这个单一对象启动,它会注册一个“authentication changed” notification消.
游戏会调用该Game Center单一处理对象的一个方法,来实现验证用户.
不论是用户被认证或者注销离开, “authentication changed” 该提醒回调函数将会被调用.
在后面的调用过程中,这个回调函数将会保持对当前用户是否正确认证进行追踪.
现在让我们朝着这个计划,前进!
认证当前的本地用户: 实施
在Cat Race Xcode project工程文件中, 在工程中添加一个新文件。到File\New\New File, 选择 iOS\Cocoa Touch\Objective-C class 这个选项, 然后点击下一步. 把该Class的父类选择为 NSObject , 点击下一步, 并命名成GCHelper.m, 并点击Finish来完成.
把GCHelper.h头文件做如下调整:
#import &Foundation/Foundation.h&
#import &GameKit/GameKit.h&
@interface GCHelper :
BOOL gameCenterA
BOOL userA
@property (assign, readonly) BOOL gameCenterA
+ (GCHelper *)sharedI
- (void)authenticateLocalU
导入GameKit的头文件, 同时创建了2个布尔型实体变量 ,— 一个是用来保持追踪iPhone设备的Game center是否可以用, 另外一个是用来保持追踪当前用户是否被正确的认证过.
同时创建了一个只读的属性,用来确认当前设备的Game Center是否可用,静态方法是用来获取这个类的实例。另一个方法是用来认证当前用户(应用启动时,用该方法进行认证).
解析来切换到GCHelper.m ,然后把下面的代码添加到@implementation 区域:
@synthesize gameCenterA
#pragma mark Initialization
static GCHelper *sharedHelper =
+ (GCHelper *) sharedInstance {
if (!sharedHelper) {
sharedHelper = [[GCHelper alloc] init];
return sharedH
同步化gameCenterAvailable属性, 然后通过这个静态实体方法获取该Class的实体对象.
我们注意到有很多方式来写某个方法,不过这可能是最简单的方式了,而且不用担心多线程,并同时实例化了该Class.
接下来在sharedInstance方法下面,添加下面的方法:
- (BOOL)isGameCenterAvailable {
// check for presence of GKLocalPlayer API
Class gcClass = (NSClassFromString(@&GKLocalPlayer&));
// check if the device is running iOS 4.1 or later
*reqSysVer = @&4.1&;
*currSysVer = [[UIDevice currentDevice] systemVersion];
BOOL osVersionSupported = ([currSysVer compare:reqSysVer
options:NSNumericSearch] != NSOrderedAscending);
return (gcClass && osVersionSupported);
这个方法的代码来自苹果的&
. 用来检查当前设备的Game Kit 是否可用.
利用之前确认一下Game Kite是否可用,该应用一直可以运行在iOS 4.0 或者更早的版本 (只是没有网络兼容).
在isGameCenterAvailable 方法的下面,添加下面的方法
- (id)init {
if ((self = [super init])) {
gameCenterAvailable = [self isGameCenterAvailable];
if (gameCenterAvailable) {
[ defaultCenter];
[nc addObserver:self
selector:@selector(authenticationChanged)
name:GKPlayerAuthenticationDidChangeNotificationName
object:nil];
- (void)authenticationChanged {
if ([GKLocalPlayer localPlayer].isAuthenticated && !userAuthenticated) {
NSLog(@&Authentication changed: player authenticated.&);
userAuthenticated = TRUE;
} else if (![GKLocalPlayer localPlayer].isAuthenticated && userAuthenticated) {
NSLog(@&Authentication changed: player not authenticated&);
userAuthenticated = FALSE;
该init方法,检查Game Center是否可用,可用情况下注册“authentication changed”notification消息提醒. 这个是重要的一步,在进行尝试验证用户之前,每次验证完毕都会调用该方法.
截至到现在的代码来看,该authenticationChanged 回调方法代码确实很简单。 主要是看用户的认证状态是否发生变化,如果发生变化更新对应的认证状态布尔变量.
值得注意的是实际的认证和取消认证中,可能被调用多次。所以只用检查userAutherticated布尔变量是不是和最后一次的相比有无变化即可.
最后添加方法来验证当前用户,添加在authenticationChanged方法的后面:
#pragma mark User functions
- (void)authenticateLocalUser {
if (!gameCenterAvailable)
NSLog(@&Authenticating local user...&);
if ([GKLocalPlayer localPlayer].authenticated == NO) {
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:nil];
NSLog(@&Already authenticated!&);
调用前面提到的authenticateWithCompletionHandler方法,告诉 Game Kit来认证当前的用户. 注意到这里没有传递完成的句柄,,因为咱们已经注册了“authentication changed”提醒消息,所以这个已经不需要了。
不错!OK – GCHelper现在包含了所有必须的用户认证代码,让咱们来用一下它。切换到AppDelegate.m ,并作如下调整:
// At the top of the file
#import &GCHelper.h&
// At the end of applicationDidFinishLaunching, right before
// the last line that calls runWithScene:
[[GCHelper sharedInstance] authenticateLocalUser];
创建了一个GCHelper的实体对象(并注册了“authentication changed”消息回调方法),并调用了认证用户的authenticateLocalUser方法.
马上要大功告成了!最后一步是添加Game Kit 框架到工程中. 大体步骤,选择CatRace project工程,在左边导航栏的树形文件的根部,出现工程的整体属性和介绍页面,工程属性页面的Target部分, 选择 Build Phases 标签, 展开“Link Binary with Libraries” 部分, 点击“+” 按钮.
选择 GameKit.framework, 并添加. 把默认类型从Require修改成Option,大体如下图:
好了! 编译并运行工程, 如果用户登录了Game Center的话,会看到大体如下图所示(当然了名字是你自己注册时候设定的昵称):
现在我们已经完成了用户的认证, 我们开始添加一些有意思的咚咚, — 匹配其他玩家,进行在线对战!
配对,配对,给我配对
通过GameCenter有2种方式来匹配用户: 程序自动寻找匹配用户,或者是用内置的匹配用户界面进行匹配.
在这个教程, 我们将利用内置一个玩家匹配用户界面. 当用户想要匹配其他玩家进行对战时,在GKMatchRequest对象中设定一些参数,并创建和显示一个KMatchmakerViewController实例对象。
让我们来看一下是如何具体实现的。首先在GCHelper.h头文件中进行部分调整:
// Add to top of file
@protocol GCHelperDelegate
- (void)matchS
- (void)matchE
- (void)match:(GKMatch *)match didReceiveData:( *)data
fromPlayer:( *)playerID;
// Modify @interface line to support protocols as follows
@interface GCHelper :
&GKMatchmakerViewControllerDelegate, GKMatchDelegate& {
// Add inside @interface
UIViewController *presentingViewC
BOOL matchS
id &GCHelperDelegate&
// Add after @interface
@property (retain) UIViewController *presentingViewC
@property (retain) GKMatch *
@property (assign) id &GCHelperDelegate&
- (void)findMatchWithMinPlayers:(int)minPlayers maxPlayers:(int)maxPlayers
viewController:(UIViewController *)viewController
delegate:(id&GCHelperDelegate&)theD
There’s a bunch of new stuff here, so let’s go over it bit by bit.
You define a protocol called GCHelperDelegate that you’ll use to notify another object of when important events happen, such as the match starting, ending, or receiving data from the other party. For this game, your Cocos2D layer will be implementing this protocol.
The GCHelper object is marked as implementing two protocols. The first is so that the matchmaker user interface can notify this object when a match is found or not. The second is so that Game Center can notify this object when data is received or the connection status changes.
Creates some new instance variables and properties to keep track of a view controller that will be used to present the matchmaker user interface, a reference to the match, whether it’s started or not, and the delegate.
Creates a new method that the Cococs2D layer will call to look for someone to play with.
Next switch to GCHelper.m and make the following changes:
// At top of file
@synthesize presentingViewC
// Add new method, right after authenticateLocalUser
- (void)findMatchWithMinPlayers:(int)minPlayers maxPlayers:(int)maxPlayers
viewController:(UIViewController *)viewController
delegate:(id&GCHelperDelegate&)theDelegate {
if (!gameCenterAvailable)
matchStarted = NO;
self.match =
self.presentingViewController = viewC
delegate = theD
[presentingViewController dismissModalViewControllerAnimated:NO];
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = minP
request.maxPlayers = maxP
GKMatchmakerViewController *mmvc =
[[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
mmvc.matchmakerDelegate =
[presentingViewController presentModalViewController:mmvc animated:YES];
This is the method that the Cocos2D layer will call to find a match. It does nothing if Game Center is not available.
It initializes the match as not started yet, and the match object as nil. It stores away the view controller and delegate for later use, and dismisses any previously existing modal view controllers (in case a GKMatchmakerViewController is already showing).
Then it moves into the important stuff. The GKMatchRequest object allows you to configure the type of match you’re looking for, such as a minimum and maximum amount of players. This method sets it to whatever is passed in (which for this game will be min 2, max 2 players).
Next it creates a new instance of the GKMatchmakerViewController with the given request, sets its delegate to the GCHelper object, and uses the passed-in view controller to show it on the screen.
The GKMatchmakerViewController takes over from here, and allows the user to search for a random player and start a game. Once it’s done some callback methods will be called, so let’s add those next:
#pragma mark GKMatchmakerViewControllerDelegate
// The user has cancelled matchmaking
- (void)matchmakerViewControllerWasCancelled:(GKMatchmakerViewController *)viewController {
[presentingViewController dismissModalViewControllerAnimated:YES];
// Matchmaking has failed with an error
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFailWithError:( *)error {
[presentingViewController dismissModalViewControllerAnimated:YES];
NSLog(@&Error finding match: %@&, error.localizedDescription);
// A peer-to-peer match has been found, the game should start
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)theMatch {
[presentingViewController dismissModalViewControllerAnimated:YES];
self.match = theM
match.delegate =
if (!matchStarted && match.expectedPlayerCount == 0) {
NSLog(@&Ready to start match!&);
If the user cancelled finding a match or there was an error, it just closes the matchmaker view.
However if a match was found, it squirrels away the match object and sets the delegate of the match to be the GCHelper object so it can be notified of incoming data and connection status changes.
It also runs a quick check to see if it’s time to actually start the match. The match object keeps track of how many players still need to finish connecting as the “expectedPlayerCount”.
If this is 0, everybody’s ready to go. Right now we’re just going to log that out – later on we’ll actually do something interesting here.
Next, add the implementation of the GKMatchDelegate callbacks:
#pragma mark GKMatchDelegate
// The match received data sent from the player.
- (void)match:(GKMatch *)theMatch didReceiveData:( *)data fromPlayer:( *)playerID {
if (match != theMatch)
[delegate match:theMatch didReceiveData:data fromPlayer:playerID];
// The player state changed (eg. connected or disconnected)
- (void)match:(GKMatch *)theMatch player:( *)playerID didChangeState:(GKPlayerConnectionState)state {
if (match != theMatch)
switch (state) {
case GKPlayerStateConnected:
// handle a new player connection.
NSLog(@&Player connected!&);
if (!matchStarted && theMatch.expectedPlayerCount == 0) {
NSLog(@&Ready to start match!&);
case GKPlayerStateDisconnected:
// a player just disconnected.
NSLog(@&Player disconnected!&);
matchStarted = NO;
[delegate matchEnded];
// The match was unable to connect with the player due to an error.
- (void)match:(GKMatch *)theMatch connectionWithPlayerFailed:( *)playerID withError:( *)error {
if (match != theMatch)
NSLog(@&Failed to connect to player with error: %@&, error.localizedDescription);
matchStarted = NO;
[delegate matchEnded];
// The match was unable to be established with any players due to an error.
- (void)match:(GKMatch *)theMatch didFailWithError:( *)error {
if (match != theMatch)
NSLog(@&Match failed with error: %@&, error.localizedDescription);
matchStarted = NO;
[delegate matchEnded];
match:didReceiveData:fromPlayer is called when another player sends data to you. This method simply forwards the data onto the delegate (which will be the Cocos2D layer in this game), so that it can do the game-specific stuff with it.
For match:player:didChangState, when the player connects you need to check if all the players have connected in, so you can start the match once they’re all in. Other than that, if a player disconnects it sets the match as ended and notifies the delegate.
The final two methods are called when there’s an error with the connection. In either case, it marks the match as ended and notifies the delegate.
OK, now that we have this code to establish a match, let’s use it in our HelloWorldLayer. Switch to HelloWorldLayer.h and make the following changes:
// Add to top of file
#import &GCHelper.h&
// Mark @interface as implementing GCHelperDelegate
@interface HelloWorldLayer : CCLayer &GCHelperDelegate&
Then switch to HelloWorldLayer.m and make the following changes:
// Add to top of file
#import &AppDelegate.h&
#import &RootViewController.h&
// Add to bottom of init method, right after setGameState
AppDelegate * delegate = (AppDelegate *) [UIApplication sharedApplication].
[[GCHelper sharedInstance] findMatchWithMinPlayers:2 maxPlayers:2 viewController:delegate.viewController delegate:self];
// Add new methods to bottom of file
#pragma mark GCHelperDelegate
- (void)matchStarted {
CCLOG(@&Match started&);
- (void)matchEnded {
CCLOG(@&Match ended&);
- (void)match:(GKMatch *)match didReceiveData:( *)data fromPlayer:( *)playerID {
CCLOG(@&Received data&);
The most important part here is in the init method. It gets the RootViewController from the AppDelegate, because that is the view controller that will present the matchmaker view controller. Then it calls the new method you just wrote on GCHelper to find a match by presenting the matchmaker view controller.
The rest is just some stub functions when a match begins or ends that you’ll be implementing later.
One last thing. By default the Cocos2D template does not contain a property for the RootViewController in the App Delegate, so you have to add one. Switch to AppDelegate.h and add the following:
@property (nonatomic, retain) RootViewController *viewC
And switch to AppDelegate.m and synthesize it:
@synthesize viewC
That’s it! Compile and run your app, and you should see the matchmaker view controller start up:
Now run your app on a different device so you have two running at the same time (i.e. maybe your simulator and your iPhone).
Important:
Make sure you are using a different Game Center account on each device, or it won’t work!
Click “Play Now” on both devices, and after a little bit of time, the matchkaker view controller should go away, and you should see something like this in your console log:
CatRace[] Authentication changed: player authenticated.
CatRace[] Player connected!
CatRace[] Ready to start match!
Congrats – you now have made a match between two devices! You’re on your way to making a networked game!
Landscape Orientation and GKMatchmakerViewController
You might have noticed that by default, the GKMatchmakerViewController appears in portrait orientation. Obviously, this is quite annoying since this Cocos2D game is in landscape!
Luckily, you can put in a patch for this with Objective-C categories by forcing the GKMatchmakerViewController to accept landscape-only orientations.
To do this, Go to File\New\New File, choose iOS\Cocoa Touch\Objective-C class, and click Next. Enter NSObject for Subclass of, click Next, name the new class GKMatchmakerViewController-LandscapeOnly.m, and click Finish.
Replace the contents of GKMatchmakerViewController-LandscapeOnly.h with the following:
#import &Foundation/Foundation.h&
#import &GameKit/GameKit.h&
@interface GKMatchmakerViewController(LandscapeOnly)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceO
Then replace the contents of GKMatchmakerViewController-LandscapeOnly.m with the following:
#import &GKMatchmakerViewController-LandscapeOnly.h&
@implementation GKMatchmakerViewController (LandscapeOnly)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) );
And that’s it! Compile and run your app and the view controller should show up in landscape mode right away:
Where To Go From Here?
Here is a&
with all of the code we’ve developed so far in this tutorial.
of the tutorial series, we’ll cover how to send data back and forth between each device in the game, and wrap up the game into an exciting cat vs. kid race!
In the meantime, if you have any questions, comments, or suggestions for future tutorials, please join the forum discussion below! And don’t forget to vote for what tutorial you’d like to see next in the sidebar! :]
I’d love to hear your thoughts!
已发表评论数()
&&登&&&陆&&
已收藏到推刊!
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见

我要回帖

更多关于 玩游戏老是自动关闭 的文章

 

随机推荐