刚入职就接到的活,之前从来没搞过,网上的文献似乎就找到了两篇,参考了一下,总算是跑起来了。多谢废话不多说。
感谢博主 Coding_life(http://blog.csdn.net/bobo823679351/article/details/42968753)的博文!!
1、创建一个iOS 项目;
2、创建一个cocos2dx项目;
3、进入已经创建好的cocos2dx项目里面,找到cocos2d这个文件夹:
并将cocos2dx文件夹复制到iOS 项目文件夹里,存放位置为与 xxx.xcodeproj文件存在同一个路径下。
4、进入iOS 项目里,右键选择添加文件,将cocos2dx的项目框架导入ios中。如图所示:这样可以看到ios项目下出现了带三角号的cocos2d_libs.xcodeproj;
5、开始导入一些framework以及设置一些参数。
因为时间长了,所以基本就是这些,哦对了,还有就是关闭arc的一些操作。
6、关于启动cocos
[super viewWillAppear:animated];
Bridge::getBridge()->setFirstPageRemove(false);
// Do any additional setup after loading the view.
cocos2d::Application *app = cocos2d::Application::getInstance();
// Initialize the GLView attributes
app->initGLContextAttrs();
cocos2d::GLViewImpl::convertAttrs();
CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [UIScreen mainScreen].bounds
pixelFormat: (__bridge NSString *)cocos2d::GLViewImpl::_pixelFormat
depthFormat: cocos2d::GLViewImpl::_depthFormat
preserveBackbuffer: NO
sharegroup: nil
multiSampling: NO
numberOfSamples: 0 ];
[eaglView setMultipleTouchEnabled:NO];
[eaglView setTag:10000];
[self.view addSubview:eaglView];
cocos2d::GLView *glview = cocos2d::GLViewImpl::createWithEAGLView((__bridge void *)eaglView);
cocos2d::Director::getInstance()->setOpenGLView(glview);
cocos2d::Director::getInstance()->setDisplayStats(false);
cocos2d::Director::getInstance()->setAnimationInterval(1.0f /60);
cocos2d::Director::getInstance()->getOpenGLView()->setDesignResolutionSize(750, 1334, ResolutionPolicy::SHOW_ALL);
cocos2d::Director::getInstance()->setGLDefaultValues();
const char* vision = [[[Info getInstance] cbVersion] UTF8String];
const char* maccode = [[UDIDFromMac uniqueGlobalDeviceIdentifier] UTF8String];
char* newversionkey = (char*)[newVersionKey UTF8String];
char* keyclienttype = (char*)[keyclientType UTF8String];
const char* sid = [[[Info getInstance] cbSID] UTF8String];
const char* suser_id = [[[Info getInstance] userId] UTF8String];
const char* suser_name = [[[Info getInstance] userName]UTF8String];
const char* suser_nickname = [[[Info getInstance] nickName]UTF8String];
Bridge::getBridge()->setUserMS(suser_id, suser_name, suser_nickname);
auto scene = LZHomeScene::createScene();
Director::getInstance()->replaceScene(scene);
//cocos2d::Application::getInstance()->run();
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[self loadRuleView];
关于启动,查看cocos在iOS中的启动方式就可以搞定了。
7、关于一些退出cocos重进黑屏的问题,查查自己的代码,在结束cocos的时候是不是只调用的end()方法,end之前是不是有一些东西没有释放掉,还有就是iOS的view关掉之前没有将cocos释放完全。
HttpClient::getInstance()->destroyInstance();
unscheduleAllSelectors();
vec.clear();
Director::getInstance()->end();
this->removeAllChildren();
__NotificationCenter::getInstance()->destroyInstance();
unscheduleAllSelectors();
this->getEventDispatcher()->removeAllEventListeners();
HttpClient::getInstance()->destroyInstance();
Director::getInstance()->end();
我这里根据log作出了相应的操作