Touch 组件
为实体提供与触摸相关的事件。
事件
- TouchStart [Data = {TouchPoint}]
- 当实体被轻触时
- TouchMove [Data = {TouchPoint}]
- 当手指在实体上移动时
- TouchCancel [Data = {TouchPoint}]
- 当触摸事件以某种方式中断时
- TouchEnd [Data = {null}]
- 当手指在实体上释放或手指离开实体时。(不传递数据)
要使用多点触控,你需要开启它Crafty.multitouch(true)
.
如果不需要多点触控,你可以使用鼠标事件代替,因为默认情况下 Crafty 在触摸输入中会触发鼠标事件。
你可以阅读更多关于 Touchevent。
- TouchEvent.touches 和 TouchEvent.changedTouches
- TouchPoint 会作为参数传递给触摸事件的回调函数。
例子
Crafty.multitouch(true);
var myEntity = Crafty.e('2D, Canvas, Color, Touch')
.attr({x: 10, y: 10, w: 40, h: 40})
.color('green')
.bind('TouchStart', function(TouchPoint){
Crafty.log('myEntity has been touched', TouchPoint);
}).bind('TouchMove', function(TouchPoint) {
Crafty.log('Finger moved over myEntity at the { x: ' + TouchPoint.realX + ', y: ' + TouchPoint.realY + ' } coordinates.');
}).bind('TouchEnd', function() {
Crafty.log('Touch over myEntity has finished.');
});