位置: 编程技术 - 正文

cocos2d-lua 学习笔记—1(cocos2dx4.0入门)

编辑:rootadmin
cocos2d-lua 学习笔记—、cocos2d-lua版本分类:普通版/Quick版,现在已经合并2、工程的创建a、Cocos Code IDE:配置环境后直接创建,如果需要创建xcode可以运行的工程,需要在Cocos Tools -> Add Native Code support...b、使用命令行 cocos new -p com.lsw.game -l lua -d . HelloWorld创建3、lua的绑定具体的原理可以参考网址:(Cocos2d-x下Lua调用自定义C&#;&#;类和函数的最佳实践) 3.6 lua -- Cocos如何绑定Lua自定义类) "cocos2d.h"class MyTestLua : public cocos2d::Ref {public: MyTestLua(){}; ~MyTestLua(){}; bool init() { return true; }; int func(int i); CREATE_FUNC(MyTestLua);};MyTestLua.cpp:#include "MyTestLua.h"int MyTestLua::func(int i) { return i &#; ;}(2)、跳转到工程目录下的文件夹 frameworks/cocos2d-x/tools/tolua,可以看到目录下有很多init的文件,这些就是我们需要绑定的所有的类的配置文件。还有一个genbindings.py的文件,这个python文件就是绑定需要的python文件。同时还需要注意的是运行这个python文件需要pyyaml、Cheetah这两个包,安装方法网上有很多。(3)、拷贝一个init文件,然后修改名字为我们需要的名字,比如MyTestLua.init(4)、修改MyTestLua.init文件的内容,主要是修改以下几个地方,init文件的内容参数具体的意义后面会介绍。[MyTestLua] prefix = MyTestLua target_namespace = lsw headers = %(cocosdir)s/../runtime-src/Classes/MyTestLua.hclasses = MyTestLua 完整的init如下:[MyTestLua]# the prefix to be added to the generated functions. You might or might not use this in your own# templatesprefix = MyTestLua# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`)# all classes will be embedded in that namespacetarget_namespace = lsw# 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-/arch-arm/usr/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc&#;&#;/4.7/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc&#;&#;/4.7/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/includeandroid_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include clang_flags = -nostdinc -x c&#;&#; -std=c&#;&#; -U __SSE__cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s/cocos/platform/androidcocos_flags = -DANDROIDcxxgenerator_headers = # extra arguments for clangextra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s # what headers to parseheaders = %(cocosdir)s/../runtime-src/Classes/MyTestLua.h# what classes to produce code for. You can use regular expressions here. When testing the regular# expression, it will be enclosed in "^$", like this: "^Menu*$".classes = MyTestLua# what should we skip? in the format ClassName::[function function]# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just# add a single "*" as functions. See bellow for several examples. A special class name is "*", which# will apply to all class names. This is a convenience wildcard to be able to skip similar named# functions from all classes.skip = rename_functions = rename_classes =# for all class names, should we remove something when registering in the target VM?remove_prefix = # classes for which there will be no "parent" lookupclasses_have_no_parents = # base classes which will be skipped when their sub-classes found them.base_classes_to_skip =# classes that create no constructor# Set is special and we will use a hand-written constructorabstract_classes = # Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'.script_control_cpp = no(5)、修改genbindings.py文件cmd_args = {'cocos2dx.ini' : ('cocos2d-x', 'lua_cocos2dx_auto'), 'MyTestLua.ini' : ('MyTestLua', 'lua_MyTestLua_auto'), ... (6)、运行python genbindings.py,运行的过程中可能会有warning,可以忽略它们(7)、等待片刻后,查看cocos2d_lua_bindings.xcodeproj,在auto文件的目录中可以看到自动生成的lua_MyTestLua_auto.cpp和lua_MyTestLua_auto.hpp,将这两个文件添加到工程中(8)、在cpp文件中由于引用了MyTestLua.h这个文件,但是这个工程的头文件中并没有查找这个的路径。需要修改一下User Header Search Paths,添加路径$(SRCROOT)/../../../../../runtime-src/Classes(9)、添加测试例子function MainScene:myAdd() local t = lsw.MyTestLua:create() print("lsw myTestLua value is "..t:func())end在onCreate方法中调用 self:myAdd()()、运行工程可以看到输出 lsw myTestLua value is 这里只是实际操作lua绑定,具体的原理和解释还需要在仔细的研究。

推荐整理分享cocos2d-lua 学习笔记—1(cocos2dx4.0入门),希望有所帮助,仅作参考,欢迎阅读内容。

cocos2d-lua 学习笔记—1(cocos2dx4.0入门)

文章相关热门搜索词:cocos2dx lua教程,cocos2dx4.0教程,cocos2d教程,cocos2d-x教程,cocos2d教程,cocos2d-x教程,cocos2dx lua教程,cocos2dx lua教程,内容如对您有帮助,希望把文章链接给更多的朋友!

Cocos2dx物理引擎(一) cocos2dx在设计之初就集成了两套物理引擎,它们是box2d和chipmunk。我目前使用的是最新版的cocos2dx3.2。引擎中默认使用的是chipmunk,如果想要改使用box2d的

coco2dx 学习笔记 -- 进度动画 ccProgressTimer ccProgressTo ccProgressFromTo ccProgressTimer是进度条类,代表了一个进度条,进度条,分两种,一种是条形的进度条,一种是圆形的进度条。ccProgressTo是进度动画类,从零播放到指定

Cocos2dx 3.2移植到Android 完全可行的方法 非常感谢原作者,我按照他写的确实成功了,期间遇到一些问题也修改了下写下来,方便后来者。点击看原文。1、安装JDK(这个不多说了,你行的)2、

标签: cocos2dx4.0入门

本文链接地址:https://www.jiuchutong.com/biancheng/368788.html 转载请保留说明!

上一篇:cocos2dx3.6动作编辑器(cocoscreator动画)

下一篇:Cocos2dx物理引擎(一)(cocos2d-x引擎)

  • 固定资产抵扣增值税何时开始
  • 项目税后现金流量的计算方法
  • 高企入库补贴要交企业所得税吗
  • 税务师证书图片
  • 小规模纳税人发票怎么做账
  • 私人企业利润怎么分配?
  • 提供给员工宿舍租赁 入账
  • 本月出库金额等于什么
  • 科研项目间接费用会计分录
  • 收到对方开错的发票怎么处理
  • 补开的银行手续费发票怎么做账
  • 期初建账以前年度损益调整怎么转?
  • 收到联营单位预收的发票
  • 一般纳税人从按照简易计税方法依照3%
  • 员工预借差旅费属于什么科目
  • 劳务派遣差额征税税率是多少
  • 营改增后装修行业税率
  • 核定征收的企业需要汇算清缴吗
  • 企业所得税核定征收最新政策
  • 个体户发票冲红应该具备什么条件
  • 报关单和发票上的公司抬头不一致
  • 管理费用的结转需要在明细账中体现吗
  • 税收筹划节税基金有哪些
  • 地下车库怎么缴费
  • 花卉租赁属于哪个税目
  • 事业单位财政补助和全额拨款有什么区别
  • 销售预付款会计分录
  • 接的网线影响传输吗
  • 电脑的c盘变红怎么回事
  • php数组函数 菜鸟
  • timit数据集
  • 何为租赁合同
  • 贷款滞纳金如何收取
  • 房地产预售收入如何缴纳所得税
  • codewriter怎么运行
  • php实现简单的登录验证
  • 金税三期税收管理系统响应异常返回信息:没有查询
  • php连接
  • 发行股票溢价计入
  • 公章的法律效力范围
  • 全卷积网络fcn详解
  • node 文件
  • 跨境电商企业要进入某个国家的市场 必须先做的工作是
  • 股本金退出要交税吗?
  • 不想预缴所得税交多了怎样先把利润转到费用
  • 旅行社的增值税税率
  • 不良品扣款入什么科目
  • 政府给的补偿款怎么做账
  • sql批量替换日期中的月份
  • sqlserver2005导出数据
  • 汇算清缴银行手续费扣除比例是多少
  • 工会支付职工福利费做账
  • 印花税是必交的吗
  • 内资非独立核算的企业
  • 短期借款的账务处理借增贷减
  • 香港的收据可以作为报销凭证吗
  • 取得工程款发票计入什么会计科目里
  • 结转公允价值变动
  • 会计基础知识归纳大全
  • sql语句基础题及答案
  • sql教程
  • ubuntu系统安装无线网卡驱动
  • 电脑提示Windows照片查看器无法打开此图片
  • ubuntu怎么禁用nouveau
  • 在mac中该如何共享文件夹
  • win7防火墙打不开错误代码6801
  • windows10x预览版
  • cocos2dx CardinalSpline和CatmullRom算法
  • cocos2d-x windows开发环境配置
  • css 3
  • win10安装node.js
  • Linux 中的cat命令
  • unity打包安卓apk
  • js 操作xml
  • 珠海市中心
  • 锂电池税收优惠政策
  • 收到unknown发来的短信
  • 各种税费申报日期
  • 浙江网上税务局申报
  • 车辆购置印花税需入固定资产吗
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设