cocos2d-html5学习之三-为sprite添加触摸事件
来源:互联网 发布:vb打印九九乘法表 编辑:程序博客网 时间:2024/05/16 11:03
cocos2d-html5学习之三-为sprite添加触摸事件
在斗地主中,使用了cc.Sprite来实现扑克,但是cc.Sprite默认并不能接收触摸事件,需要手动将它注册到事件分配器中。
1. 在onEnter中注册为代理,由于扑克牌会产生重叠,在选择的时候不能让触摸事件传递到被覆盖的牌上,因此不能使用standardTargetedDelegate。
onEnter:function(){ cc.registerTargetedDelegate(0, true, this); this._touchEnabled=true; this._super(); }
2. 实现其它几个触摸事件,其中onTouchBegan中需要返回true,否则不会调用后面的onTouchEnded方法。
onTouchBegan:function(touches,event){ var rect = this.touchRect(); var point = touches.getLocation(); if(cc.rectContainsPoint(this.touchRect(),touches.getLocation())){ this._touchBegan=true; return true; } return false; }
onTouchEnded:function(touches,event){ if(this._touchBegan){ this._touchBegan=false; if(this.active) { this.active = false; this.setPositionY(this.getPositionY() - 30); } else { this.active = true; this.setPositionY(this.getPositionY() + 30); } } }
0 0
- cocos2d-html5学习之三-为sprite添加触摸事件
- cocos2d-html5学习之三-为sprite添加触摸事件
- cocos2d-x基础学习--添加触摸事件
- Cocos2d-iphone 为sprite添加双击的事件响应
- 为精灵添加触摸事件
- cocos2d开发之触摸事件
- Cocos2d-X之触摸事件
- Cocos2d-html5教程之三 拖拽移动Sprite |小一
- Cocos2d-x学习之---自定义图标(带触摸事件)
- cocos2d点滴-添加触摸事件
- 【Cocos2d-html5游戏引擎学习笔记(5)】Sprite精灵渲染
- cocos2d-x 3.x之触摸事件
- COCOS2d中添加UIButton不响应触摸事件---iOS开发之最灵异事件之2
- 【Cocos2d入门教程六】Cocos2d-x事件篇之触摸
- 在cocos2d上添加UIView,触摸事件往下传递
- cocos2d-x添加触摸层阻止后端事件
- 为View添加触摸事件 添加tag 用于判断View
- html5 触摸事件
- C语言单链表倒置,头插法详细介绍
- 快速排序
- com.ibm.db2.jcc.b.DisconnectException: A communication error has been detected. Communication protoc
- 在Android环境上测试第一个PhoneGap程序
- Square Coins HDU(1398)(典型的母函数)
- cocos2d-html5学习之三-为sprite添加触摸事件
- 举例讲解JAVA中的堆和栈
- ReplaceText
- 黑马程序员_Java基础[22]_异常总结
- 大端序和小端序
- 希尔排序
- cocos2d-html5教程之-键盘事件和touch事件
- 比float更好的网页布局之inline-block
- 第九周项目三-分数类