CollisionManager
类型
一个简单的碰撞组件管理类,用于处理节点之间的碰撞组件是否产生了碰撞,并调用相应回调函数。
索引
属性(properties)
enabled
Boolean
是否开启碰撞管理,默认为不开启enabledDrawBoundingBox
Boolean
是否绘制碰撞组件的包围盒,默认为不绘制enabledDebugDraw
Boolean
是否绘制碰撞组件的形状,默认为不绘制
方法
on
注册事件目标的特定事件类型回调。off
删除之前用同类型,回调,目标或 useCapture 注册的事件监听器,如果只传递 type,将会删除 type 类型的所有事件监听器。targetOff
在当前 EventTarget 上删除指定目标(target 参数)注册的所有事件监听器。once
注册事件目标的特定事件类型回调,回调会在第一时间被触发后删除自身。dispatchEvent
分发事件到事件流中。emit
该对象直接发送事件, 这种方法不会对事件传播到任何其他对象。
Details
属性(properties)
enabled
是否开启碰撞管理,默认为不开启
meta | description |
---|---|
类型 | Boolean |
定义于 | cocos2d/core/collider/CCCollisionManager.js:92 |
enabledDrawBoundingBox
是否绘制碰撞组件的包围盒,默认为不绘制
meta | description |
---|---|
类型 | Boolean |
定义于 | cocos2d/core/collider/CCCollisionManager.js:100 |
enabledDebugDraw
是否绘制碰撞组件的形状,默认为不绘制
meta | description |
---|---|
类型 | Boolean |
定义于 | cocos2d/core/collider/CCCollisionManager.js:433 |
方法
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