触摸事件
- 触摸事件类型: START, MOVED, ENDED(物体内), CANCEL(物体外);
- 监听触摸事件: node.on(类型, callback, target(回掉函数的this), [useCapture]);
- 关闭触摸事件: node.off(类型, callback, target(回掉函数的this), [useCapture]);
- targetOff (target): 移除所有的注册事件;
- 回掉函数的参数设置 function(t(cc.Touch))
- cc.Touch: getLocation返回触摸的位置;getDelta返回距离上次的偏移;
- cc.Event: stopPropagationImmediate/stopPropagation 停止事件的传递;
- 事件冒泡: 触摸事件支持节点树的事件冒泡,会从当前前天往上一层一层的向父节点传送;
- 完成物体跟随手指触摸的案例;
键盘事件
- cc.SystemEvent.on(type, function, target, useCapture); type: cc.SystemEvent.EventType.KEY_DOWN 按键按下;