cocos2d-js 类之家传递事件的方法
来源:互联网 发布:网络文件传输协议 编辑:程序博客网 时间:2024/04/30 06:34
方法一:(子节点向父节点,制作事件传递)
A:onLoad: function () { var self = this; self.node.on(cc.Node.EventType.TOUCH_START, function (event) { cc.log("mouse_up " + self.index +">"+self.isS); if (self.isS == 0) { self.playClick(); var event = new cc.Event.EventCustom('selectRight', true); event.setUserData(self.index); self.node.dispatchEvent(event); } }, self); },B, self.node.on('selectRight', function (event) { self.pr.barSprite.getComponent(cc.Animation).play('barShowAnimate'); self.pr.progress -= 0.04; event.stopPropagation(); });
方法二:(把要实现的方法作为参数在子节点‘初始化’的时候传递)
A:cc.Class({ extends: cc.Component, properties: { callFunction:cc.Function, passSelf:cc.Class }, // use this for initialization onLoad: function () { var self = this; self.node.on(cc.Node.EventType.TOUCH_START, function (event) { self.callFunction(self.index,self.currentindex,self.passSelf); }); }, init:function (i,ci,callFunction,passSelf) { self.callFunction = callFunction; self.passSelf = passSelf },});B:smallNode.getComponent('smallItem').init(i,array[i],self.callFunction,self);callFunction : function(index,cindex,passSelf ){..实现方法..},
方法三:二的优化
A:cc.Class({ extends: cc.Component, properties: { passSelf:cc.Class }, // use this for initialization onLoad: function () { var self = this; self.node.on(cc.Node.EventType.TOUCH_START, function (event) { self.callFunction(self.index,self.currentindex); }); }, init:function (i,ci,passSelf) { this.passSelf = passSelf }, callFunction : function(index,cindex){ var self = this.passSelf;..实现方法..},});B:smallNode.getComponent('smallItem').init(i,array[i],self);
2 0
- cocos2d-js 类之家传递事件的方法
- cocos2d-js的自定义事件的两种创建方法
- cocos2d-js的自定义事件的两种创建方法
- js“DOM事件”之鼠标事件、js的测试方法、js代码的放置位置
- cocos2d js的一些方法
- Cocos2d-js 触摸事件的简单封装
- Cocos2d-JS键盘事件
- cocos2d-js 事件交互
- Cocos2d-JS 触摸事件
- cocos2d - JS 点击事件
- js 事件绑定的方法
- js 事件绑定的方法
- JS事件绑定的方法
- js事件绑定的方法
- js 事件绑定的方法
- JS事件绑定的方法
- js 事件绑定的方法
- JS 之document常用方法属性事件
- web app禁用手机浏览器缓存
- [电影]《指环王》新老三部曲完全赏析(双塔)
- 几种服务器模型对比分析
- JSP页面编译时遇到Propertty 'XXX' not found on type java.lang.String错误的解决办法
- Tyvj1754 BZOJ1085[SCOI2005]骑士精神
- cocos2d-js 类之家传递事件的方法
- Leetcode 52 N-Queens II
- Android调用微信登陆、分享、支付,android调用
- 疏忽导致易接SDK OpenGL error
- transient关键字使用总结
- 设计模式-单例模式
- Linux常用命令-crontab:
- sigsuspend的理解
- freeswitch 媒体早期协商模式分析