1,编译环境配置
游戏大厅使用 Cocos Creator 开发
CocosCreator 版本号: v1.9.3
下载地址: http://www.cocos.com/history
xCode 请使用xCode10 或 xCode 9.3+
项目最低支持IOS系统版本号: IOS9.0
4,xCode 工程集成及配置说明
CocosCreator 打包生成的xCode 工程目录路径为:
/GameHall/build/jsb-default/frameworks/runtime-src/proj.ios_mac
原始项目未开启ARC需手动开启ARC
Deployment Target 请设置为 9.0
main.m 文件修改为 main.mm 后缀
main.mm 中代码修改为:
#import <UIKit/UIKit.h>
#import "AppController.h"
//int main(int argc, char *argv[]) {
//
// NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// int retVal = UIApplicationMain(argc, argv, nil, @"AppController");
// [pool release];
// return retVal;
//}
int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppController class]));
}
}
2 IOS原生静态库项目集成至Cocos Creator Xcode 项目中说明
由于项目部分功能如:游戏下载/游戏解压/游戏加载 需要使用IOS原生代码支持,所以把这一部分代码封装为静态库以便Cocos 生成的原始工程调用,同时也可以加快编译及打包速度
2.1, xCode工程 配置
config.hpp 文件中修改(修复部分机型设备上偶现的崩溃问题)
SCRIPT_ENGINE_TYPE 修改为 SM 引擎
#define SCRIPT_ENGINE_NONE 0
#define SCRIPT_ENGINE_SM 1
#define SCRIPT_ENGINE_V8 2
#define SCRIPT_ENGINE_JSC 3
#define SCRIPT_ENGINE_CHAKRACORE 4
#if defined(__APPLE__) // macOS and iOS use JavaScriptCore
#define SCRIPT_ENGINE_TYPE SCRIPT_ENGINE_SM/*SCRIPT_ENGINE_JSC*/
#elif defined(ANDROID) || (defined(_WIN32) && defined(_WINDOWS)) // Windows and Android use V8
#define SCRIPT_ENGINE_TYPE SCRIPT_ENGINE_V8
#else
#error "Unknown Script Engine"
#endif
other link flag 中配置 -all_load $(inherited)
Build Phases -> Link Binary With Libraries 中添加下列依赖库
其中(注意):
1 libstdc++.tbd 库在xCode10 中被弃用,请参考如下添加方法 http://www.cocoachina.com/cms/wap.php?action=article&id=23749 把libstdc++.tbd拷贝到xCode10 对应目录下(注意真机和模拟器需要分别拷贝) (xCode10中可不添加)
2 libjs_static.a 和 libmozglue.a 为cocos 引擎自带库文件,位置如下,请手动拖至xCode 中
3,Cocos 引擎在xCode 工程中存在的一些bugs 修复:
3.1 CCEAGLView-ios.mm 文件中 (修复键盘弹出时转屏界面错乱问题)
-(void) doAnimationWhenKeyboardMoveWithDuration:(float)duration distance:(float)dis
{
[UIView beginAnimations:nil context:nullptr];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:duration];
[UIView setAnimationBeginsFromCurrentState:YES];
//NSLog(@"[animation] dis = %f, scale = %f \n", dis, cocos2d::GLView::getInstance()->getScaleY());
if (dis < 0.0f) dis = 0.0f;
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
dis *= glview->getScaleY();
dis /= self.contentScaleFactor;
#if defined(CC_TARGET_OS_TVOS)
self.frame = CGRectMake(originalRect_.origin.x, originalRect_.origin.y - dis, originalRect_.size.width, originalRect_.size.height);
#else
/*
switch (getFixedOrientation([[UIApplication sharedApplication] statusBarOrientation]))
{
case UIInterfaceOrientationPortrait:
self.frame = CGRectMake(originalRect_.origin.x, originalRect_.origin.y - dis, originalRect_.size.width, originalRect_.size.height);
break;
case UIInterfaceOrientationPortraitUpsideDown:
self.frame = CGRectMake(originalRect_.origin.x, originalRect_.origin.y + dis, originalRect_.size.width, originalRect_.size.height);
break;
case UIInterfaceOrientationLandscapeLeft:
self.frame = CGRectMake(originalRect_.origin.x - dis, originalRect_.origin.y , originalRect_.size.width, originalRect_.size.height);
break;
case UIInterfaceOrientationLandscapeRight:
self.frame = CGRectMake(originalRect_.origin.x + dis, originalRect_.origin.y , originalRect_.size.width, originalRect_.size.height);
break;
default:
break;
}
*/
switch (getFixedOrientation([[UIApplication sharedApplication] statusBarOrientation]))
{
case UIInterfaceOrientationPortrait:
self.frame = CGRectMake(originalRect_.origin.x, originalRect_.origin.y - dis, self.frame.size.width, self.frame.size.height);
break;
case UIInterfaceOrientationPortraitUpsideDown:
self.frame = CGRectMake(originalRect_.origin.x, originalRect_.origin.y + dis, self.frame.size.width, self.frame.size.height);
break;
case UIInterfaceOrientationLandscapeLeft:
self.frame = CGRectMake(originalRect_.origin.x - dis, originalRect_.origin.y , self.frame.size.width, self.frame.size.height);
break;
case UIInterfaceOrientationLandscapeRight:
self.frame = CGRectMake(originalRect_.origin.x + dis, originalRect_.origin.y , self.frame.size.width, self.frame.size.height);
break;
default:
break;
}
#endif
[UIView commitAnimations];
}
3.2 config.hpp 文件中(修复部分机型设备上偶现的崩溃问题) (同4.2.3)
SCRIPT_ENGINE_TYPE js脚本引擎修改为 SM 引擎
#define SCRIPT_ENGINE_NONE 0
#define SCRIPT_ENGINE_SM 1
#define SCRIPT_ENGINE_V8 2
#define SCRIPT_ENGINE_JSC 3
#define SCRIPT_ENGINE_CHAKRACORE 4
#if defined(__APPLE__) // macOS and iOS use JavaScriptCore
#define SCRIPT_ENGINE_TYPE SCRIPT_ENGINE_SM/*SCRIPT_ENGINE_JSC*/
#elif defined(ANDROID) || (defined(_WIN32) && defined(_WINDOWS)) // Windows and Android use V8
#define SCRIPT_ENGINE_TYPE SCRIPT_ENGINE_V8
#else
#error "Unknown Script Engine"
#endif