【H5+ & Quick-cocos2dx整合】之iOS 三 集成Quick-Cocos2dx SDK

前端之家收集整理的这篇文章主要介绍了【H5+ & Quick-cocos2dx整合】之iOS 三 集成Quick-Cocos2dx SDK前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

添加Quick-cocos的依赖项目

依赖项目位于下载的Quick-Cocos2dx目录下

/build/cocos2d_libs.xcodeproj

/cocos/scripting/lua-bindings/proj.ios_mac/ cocos2d_lua_bindings.xcodeproj

拖动这两个文件添加到项目下

Target à BuildPhases à Target Dependencies

单击“+”添加libcocos2d 和 libluacocos2d


添加Lib文件libcocos2d.a和libluacocos.a

添加文件引用

/quick/lib/quick-src

注:需要手动移除在/ extra/platform中与ios不相关的引用(待写。。。)

添加引用包路径

引入Frameworks:

CoreMotion.framework

StoreKit.framework

GameController.framework

OpenAL.framework

设置Header Search Paths

$(inherited)

$(QUICK_V3_ROOT)/cocos

$(QUICK_V3_ROOT)/cocos

$(QUICK_V3_ROOT)/cocos/base

$(QUICK_V3_ROOT)/cocos/physics"$(QUICK_V3_ROOT)/cocos/math/kazmath""$(QUICK_V3_ROOT)/cocos/2d"

"$(QUICK_V3_ROOT)/cocos/ui"

"$(QUICK_V3_ROOT)/cocos/network""$(QUICK_V3_ROOT)/cocos/audio/include""$(QUICK_V3_ROOT)/cocos/editor-support""$(QUICK_V3_ROOT)/extensions"

"$(QUICK_V3_ROOT)/external""$(QUICK_V3_ROOT)/external/chipmunk/include/chipmunk""$(QUICK_V3_ROOT)/external/lua/luajit/include""$(QUICK_V3_ROOT)/external/lua/tolua""$(QUICK_V3_ROOT)/external/glfw3/include/mac""$(QUICK_V3_ROOT)/external/lua/luajit/include""$(QUICK_V3_ROOT)/cocos/scripting/lua-bindings/manual""$(QUICK_V3_ROOT)/cocos/scripting/lua-bindings/auto""$(QUICK_V3_ROOT)/cocos/scripting/lua-bindings/manual"$(QUICK_V3_ROOT)/quick/lib/quick-src"$(QUICK_V3_ROOT)/quick/lib/quick-src/extra""$(QUICK_V3_ROOT)/external/protobuf-lite/src"

设置User Header Search Paths:

$(inherited)

"$(QUICK_V3_ROOT)/cocos/platform/ios""$(QUICK_V3_ROOT)/external/curl/include/ios"

设置Framework Search Paths

CCLibs(该目录自行创建,只包含一个opengl.framework,该文件在cocos2dx中能找到)

编译参数配置:

Objective-CAutomatic Reference Counting à No

Always SearchUser Paths à Yes

PrecompilePrefix Header à Yes

Prefix Header à H5_Cocos_Integrate/Prefix.pch

Prefix.pch

#ifdef __OBJC__

#import <Foundation/Foundation.h>

#import <UIKit/UIKit.h>

#endif

设置宏变量(Preprocessor Macros)

Debug:

$(inherited)

COCOS2D_DEBUG=1

USE_FILE32API

CC_LUA_ENGINE_ENABLED=1

CC_ENABLE_CHIPMUNK_INTEGRATION=1

CC_TARGET_OS_IPHONE

Release:

CC_TARGET_OS_IPHONE

$(inherited)

CC_ENABLE_CHIPMUNK_INTEGRATION=1

CC_LUA_ENGINE_ENABLED=1

USE_FILE32API

集成cocos2dx代码

代码生成

可以通过quick-cocos2dx创建一个工程,找到下图中四个类文件,引用到项目中。


注:AppDelegate.cpp改为AppDelegate.mm,一是为了OC和C++混编引用自己定义的app管理类,便于h5和cocos2dx之间的协调工作。

添加Demo资源

同样通过Quick-Cocos2dx创建一个demo工程,拷贝其中res和src目录到项目中,并引用。

可以通过Copy Bundle Resources添加引用。

错误示例

错误:oc编译参数错误

quick-src/extra/platform/ios/json/SBJSON.m:46:17:error: 'release' is unavailable: not available in automatic reference countingmode

[jsonWriter release];

解决方法:Objective-C Automatic Reference Counting à No

错误:设置宏变量

/Users/katichar/H5Plus_QuickCocos2dx_Integrate/frameworks/CCLibs/OpenGL.framework/Versions/A/Headers/glext.h:2289:49:Unknown type name 'GLdouble'; did you mean 'double'?

debug:

$(inherited) COCOS2D_DEBUG=1 USE_FILE32APICC_LUA_ENGINE_ENABLED=1 CC_ENABLE_CHIPMUNK_INTEGRATION=1 CC_TARGET_OS_IPHONE

release:

CC_TARGET_OS_IPHONE $(inherited)CC_ENABLE_CHIPMUNK_INTEGRATION=1 CC_LUA_ENGINE_ENABLED=1 USE_FILE32API

错误:缺少StoreKit.framework

"_OBJC_CLASS_$_SKPayment",referenced from:

objc-class-ref in CCStoreIOS.o

错误:缺少CoreMotion.framework

"_OBJC_CLASS_$_CMMotionManager",referenced from:

objc-class-ref in libcocos2dioS.a(CCDevice-ios.o)


删除部分:

protobuf—pb.o

md5


TargetàBuildSettingsàApple LLVM7.1 – Language à

Precompile Prefix Header àYes

Prefix Header à H5_Cocos_Integrate/Prefix.pch

原文链接:https://www.f2er.com/cocos2dx/339362.html

猜你在找的Cocos2d-x相关文章