cocos-js 自动绑定C++(2)代码部分

代码部分一共有3中文件
     1 .c++文件,就是自己需要的c++文件。 .h 和 .cpp
  1. 自动生成的c++文件 。可供js 调用的 .hpp 和 .cpp文件 (连接js 和cpp)
  2. 自动生成的 .js 文件 ,供自己代码中的js 直接调用


  • 写c++文件,将需要调用的C++文件(.h 和 .cpp)copy到 CocosCreator\resources\cocos2d-x\tools\tojs 目录下(其实位置可以任意,只需要在后面的配置文件中正确指向就可以)
            
            测试代码: 就是在控制台输出一句话

                .h 文件
                    //   jsbTest.h
                    #ifndef __JSB_TEST_H__
                    #define __JSB_TEST_H__
                    #include "cocos2d.h"
                    class jsbTest
                    {
                        public:
                           static void testlog();
                    };

                    #endif //__JSB_TEST_H


                .cpp 文件
                     //   jsbTest.cpp
                    #include "jsbTest.h"
                    USING_NS_CC;
                    void jsbTest::testlog()
                    {
                        CCLOG("jsbinding succeed!");
                    } 
                    
  • 写配置文件.ini   (其实就是复制修改,找一个原有的.ini文件 修改就好   )   配置文件路径: CocosCreator\resources\cocos2d-x\tools\tojs
            名字可以任意取 ,在需要执行的python文件中指定就行   这里设置 jsbTest (和c++文件名一致 方便管理)
                    [ jsbTest]
                    # the prefix to be added to the generated functions. You might or might not use this in your own
# templates
prefix = jsbTest 
# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`)
# all classes will be embedded in that namespace
target_namespace =
# the native namespace in which this module locates, this parameter is used for avoid conflict of the same class name in different modules, as "cocos2d::Label" <-> "cocos2d::ui::Label".
cpp_namespace =
android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.8/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.9/include
android_flags = -D_SIZE_T_DEFINED_
clang_headers = -I%(clangllvmdir)s/%(clang_include)s
clang_flags = -nostdinc -x c++ -std=c++11 -U __SSE__
cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s/cocos/platform/android -I%(cocosdir)s/external/sources
cocos_flags = -DANDROID
cxxgenerator_headers =
# extra arguments for clang
extra_arguments = %(android_headers)s %
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值