cocos2dx lua中使用class实现继承api中的类
来源:互联网 发布:淘宝怎么天天特价 编辑:程序博客网 时间:2024/04/29 09:57
如果需要扩展api中的类时,使用继承的方式,需要重写的就重写,需要扩展就扩展
直接上代码,代码中有解释
require "extern" --使用class方法需要的extern.lua模块--调用父类方法function getSuperMethod(table, methodName) local mt = getmetatable(table) local method = nil while mt and not method do method = mt[methodName] if not method then local index = mt.__index if index and type(index) == "function" then method = index(mt, methodName) elseif index and type(index) == "table" then method = index[methodName] end end mt = getmetatable(mt) end return methodend--自定义类继承sprite,前提是这个sprite必须先绑定好c++中的spriteMyCustom = class("MyCustom",function(filename) --通过返回一个sprite实现继承sprite类, return cc.Sprite:create(filename) --这里的function就是下面的MyCustom.newend)MyCustom.__index = MyCustom --索引访问MyCustom.aaa = 0 --定义属性及对应值function MyCustom:create(filename , aaa) local mySpr = MyCustom.new(filename) --这里使用的是''.",不是":" self.aaa = aaa --设置属性值 return mySprend-- 实现重写父类方法function MyCustom:setVisible(visible) getSuperMethod(self, "setVisible")(self, visible) --调用父类方法并传递参数 print("override setVisible method")end
0 0
- cocos2dx lua中使用class实现继承api中的类
- cocos2dx lua class 继承问题
- cocos2dx中lua实现继承详解
- cocos2dx中lua实现继承详解
- cocos2dx中lua实现继承详解
- cocos2dx开发中的lua继承
- [cocos2dx]cocos2dx-lua中class语法
- cocos2dx-lua中实现面向对象的封装继承
- cocos2dx lua继承C++类
- Lua_在Lua中继承Cocos2dx的C++类
- 在Lua中继承Cocos2dx的C++类
- quick cocos2dx基础(一):lua类及继承,class解析
- cocos2dx + lua 中实现 lua的MVC
- Cocos2dx-lua 实现lua面向对象编程,并继承CCSprite
- lua中实现类的继承
- Cocos2dx-lua -- 入门-class
- cocos2dx-lua class
- cocos2dx Lua继承c++类的方法
- 【OJ】(二)---L---线性表
- java学习笔记1
- C++语言笔记系列之十一——友元函数与拷贝构造函数
- NYOJ 636 世界末日
- (多)继承中的构造与析构
- cocos2dx lua中使用class实现继承api中的类
- 字典树 之 hdu 1251
- 【每天总结一个ios开发心得】对于Retain和Assign属性的理解
- 动态代理
- Map 遍历方式-以及优缺点
- SpringMVC入门之注解式控制器
- aspx 页面间传值
- [日记]2014-6-28
- 数据挖掘、数据分析、海量数据处理的面试题(总结july的博客)