SystemEvent
类型
继承于 EventTarget
系统事件,它目前支持按键事件和重力感应事件
索引
方法
setAccelerometerEnabled
是否启用加速度计事件setAccelerometerInterval
设置加速度计间隔值on
注册事件目标的特定事件类型回调。off
删除之前用同类型,回调,目标或 useCapture 注册的事件监听器,如果只传递 type,将会删除 type 类型的所有事件监听器。targetOff
在当前 EventTarget 上删除指定目标(target 参数)注册的所有事件监听器。once
注册事件目标的特定事件类型回调,回调会在第一时间被触发后删除自身。dispatchEvent
分发事件到事件流中。emit
该对象直接发送事件, 这种方法不会对事件传播到任何其他对象。
Details
方法
setAccelerometerEnabled
是否启用加速度计事件
meta | description |
---|---|
定义于 | cocos2d/core/event/system-event.js:93 |
参数列表
isEnable
Boolean
setAccelerometerInterval
设置加速度计间隔值
meta | description |
---|---|
定义于 | cocos2d/core/event/system-event.js:103 |
参数列表
interval
Number
on
注册事件目标的特定事件类型回调。
meta | description |
---|---|
返回 | Function |
定义于 | cocos2d/core/event/event-target.js:218 |
参数列表
type
String A string representing the event type to listen for.callback
Function The callback that will be invoked when the event is dispatched.The callback is ignored if it is a duplicate (the callbacks are unique).
event
Event event
target
Object The target (this object) to invoke the callback, can be nulluseCapture
Boolean When set to true, the capture argument prevents callbackfrom being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false, callback will NOT be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked when event's eventPhase attribute value is AT_TARGET.
示例
node.on(cc.Node.EventType.TOUCH_END, function (event) {
cc.log("this is callback");
}, node);
off
删除之前用同类型,回调,目标或 useCapture 注册的事件监听器,如果只传递 type,将会删除 type 类型的所有事件监听器。
meta | description |
---|---|
定义于 | cocos2d/core/event/event-target.js:275 |
参数列表
type
String A string representing the event type being removed.callback
Function The callback to remove.target
Object The target (this object) to invoke the callback, if it's not given, only callback without target will be removeduseCapture
Boolean Specifies whether the callback being removed was registered as a capturing callback or not.If not specified, useCapture defaults to false. If a callback was registered twice, one with capture and one without, each must be removed separately. Removal of a capturing callback does not affect a non-capturing version of the same listener, and vice versa.
示例
// register touchEnd eventListener
var touchEnd = node.on(cc.Node.EventType.TOUCH_END, function (event) {
cc.log("this is callback");
}, node);
// remove touch end event listener
node.off(cc.Node.EventType.TOUCH_END, touchEnd, node);
// remove all touch end event listeners
node.off(cc.Node.EventType.TOUCH_END);
targetOff
在当前 EventTarget 上删除指定目标(target 参数)注册的所有事件监听器。 这个函数无法删除当前 EventTarget 的所有事件监听器,也无法删除 target 参数所注册的所有事件监听器。 这个函数只能删除 target 参数在当前 EventTarget 上注册的所有事件监听器。
meta | description |
---|---|
定义于 | cocos2d/core/event/event-target.js:330 |
参数列表
target
Object The target to be searched for all related listeners
once
注册事件目标的特定事件类型回调,回调会在第一时间被触发后删除自身。
meta | description |
---|---|
定义于 | cocos2d/core/event/event-target.js:352 |
参数列表
type
String A string representing the event type to listen for.callback
Function The callback that will be invoked when the event is dispatched.The callback is ignored if it is a duplicate (the callbacks are unique).
event
Event event
target
Object The target (this object) to invoke the callback, can be nulluseCapture
Boolean When set to true, the capture argument prevents callbackfrom being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false, callback will NOT be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked when event's eventPhase attribute value is AT_TARGET.
示例
node.once(cc.Node.EventType.TOUCH_END, function (event) {
cc.log("this is callback");
}, node);
dispatchEvent
分发事件到事件流中。
meta | description |
---|---|
定义于 | cocos2d/core/event/event-target.js:397 |
参数列表
event
Event The Event object that is dispatched into the event flow
emit
该对象直接发送事件, 这种方法不会对事件传播到任何其他对象。
meta | description |
---|---|
定义于 | cocos2d/core/event/event-target.js:411 |
参数列表
message
String the message to senddetail
Any whatever argument the message needs