大佬教程收集整理的这篇文章主要介绍了Cocos2d-Lua(Quick-Cocos2d-x)集成第三方SDK(二),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在上一篇文章中,我们介绍了,怎么集成友盟的Cocos2d-x版本SDK,接下来我们来说下怎么将友盟的C++接口导出到Lua中使用。
引擎版本: Quick-Cocos2d-x 3.3 开发系统: Windows 7 64bit
我们打开libMobClickCpp\include文件夹可以看到里面有两个文件,分别是:
打开这两个文件看他们的内容可以发现,MobClickJniHelper.h的内容中只有一个
|
而在MobClickCpp.h中包含了我们基本上能使用的所有的umeng的接口,所以我们需要导出的接口其实就是MobClickCpp中的接口。
新建一个MobClickLua.tolua文件,将下面的内容复制进去,我们再来详细分析下:
class
MobClickCpp {
public
:
void
event(
const
char
* eventId,153)!important; BACkground:none!important">const
char
* label = null);
Unkonwn = 0,
@H_348_24@male = 1,
Female = 2,
};
void
setUserInfo(
const
char
* userId,Sex sex,
int
age,153)!important; BACkground:none!important">const
char
* platform);
void
use(
:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-size:1em!important; min-height:inherit!important; color:rgb(0,
double
pricE);
void
bonus(
:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-size:1em!important; min-height:inherit!important; color:rgb(0,
double
price,
int
sourcE);
};
|
我们可以看到上面的内容基本上都是MobClickCpp.h文件中的接口。我们现在来详细说下这几个部分的意思。
第一部分的代码是:
这里的代码是引用代码,需要包含的头文件可以填到这里。
第二部分是这一句:
我们打开MobClickCpp.h的内容可以看到里面定义了一个命名空间为
为了能在转出来的.cpp文件中使用umeng的接口,我们需要把命名空间引用过去。所以这里加了这一句话方便在.cpp文件中使用umeng命名空间。
第三部分就是我们具体的类的定义了,这里最好是直接拷贝.h文件中的类的声明。当然,你想自己定义一个类来作为中间层,也可以声明为自定义的层。这个时候记得要修改第一部分和第二部分的代码。
在Quick-Cocos2d-x 3.3中自带了tolua++工具,位置在[QUICK_V3_ROOT]/quick/bin下面的win32或者是mac下,我们最好将它们都添加到系统的PATH环境变量中,方便下次使用。
在命令行下直接输入:
可以看到tolua++的帮助信息
-v : print version information.
-o file : set output file;
default
is stdout.
-H file : create include file.
-n name : set package name;
default
is input file root name.
-p : parse only.
-P : parse and print structure information (
for
debug).
-1 : substract 1 to operator[] index (
for
compatibility with tolua5).
-L file : run lua file (with dofile()) before doing anything.
constructors (
for
compatibility with tolua5)
-W : disable warnings
for
unsupported features (
for
compatibility
with tolua5)
-C : disable cleanup of included lua code (
for
easier debugging)
-E value[=value] : add extra values to the luastate
-q : don't print warnings to the console
Should the input file be omitted,stdin is assumed;
in that
case
,the package name must be explicitly set.
aaaaaa
|
了解上面这些信息后,我们执行命令:
tolua++ -o lua_binding_MobClickCpp.cpp -H lua_binding_MobClickCpp.h MobClickCpp.tolua
|
执行完成后将会生成两个文件:
生成的两个文件就是我们将.tolua的描述信息转为lua_binding的接口之后的.cpp和.h文件,这两个文件既可以放到引擎的目录下也可以放到工程目录下,这里为了描述方面我就把它们放到工程目录下了。
拷贝上面的两个文件到工程下的umeng\frameworks\runtime-src\Classes
目录,然后打开proj.android_no_anysdk\jni下的Android.mk文件,给LOCAL_SRC_FILES
加上../../Classes/lua_binding_MobClickCpp.cpp \
,加上之后的LOCAL_SRC_FILES
内容如下:
打开proj.android工程中的AppActivity.java文件,在函数onCreate
中添加下面的语句:
打开AppDelegate.cpp文件,添加头文件
然后再在函数bool AppDelegate::applicationDidFinishLaunching()
中添加以下代码:
注意上面这一句添加的位置必须要在获取到lua_State之后。
接着分别在AppDelegate::applicationDidEnterBACkground
和AppDelegate::applicationWillEnterForeground
中分别添加
和
改完C++代码后,build_native
编译C++代码。稍等片刻,我们等待C++编译完。
我们打开Quick-Cocos2d-x工程中的MyApp.lua代码文件,修改function MyApp:run()
的内容为:
这里的5539bb6767e58e62eb000288
是我们在umeng官网上创建APP的时候所给的AppKey。GooglePlay
为我们所使用的渠道。
打开Eclipse,在手机上运行工程,我们可以在后台看到umeng的数据
打开应用的详细页面,点击渠道分析,里面有一个渠道列表的子选项,点击之后我们可以看到我们上传的渠道用户数量:
好了,友盟的C++版本在Lua的使用就介绍到这里,其他umeng的接口大家可以看下R_478_11845@obClickCpp.h文件中查看接口说明。
下一篇我们看在Lua里直接使用Java版本的umeng接口。
以上是大佬教程为你收集整理的Cocos2d-Lua(Quick-Cocos2d-x)集成第三方SDK(二)全部内容,希望文章能够帮你解决Cocos2d-Lua(Quick-Cocos2d-x)集成第三方SDK(二)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。