CollisionManager
Class
Module: cc
A simple collision manager class.
It will calculate whether the collider collides other colliders, if collides then call the callbacks.
Examples
let manager = cc.director.getCollisionManager();
manager.enabled = true;
manager.enabledDebugDraw = true;
manager.enabledDrawBoundingBox = true;
onCollisionEnter: function (other, self) {
this.node.color = cc.Color.RED;
this.touchingNumber ++;
},
onCollisionStay: function (other, self) {
console.log('on collision stay');
},
onCollisionExit: function (other, self) {
this.touchingNumber --;
if (this.touchingNumber === 0) {
this.node.color = cc.Color.WHITE;
}
}
Index
Properties
Methods
hasEventListener
Checks whether the EventTarget object has any callback registered for a specific type of event.
on
Register an callback of a specific event type on the EventTarget.
off
Removes the listeners previously registered with the same type, callback, target and or useCapture,...
targetOff
Removes all callbacks previously registered with the same target (passed as parameter).
once
Register an callback of a specific event type on the EventTarget,...
dispatchEvent
Send an event with the event object.
Details
Properties
enabled
enabledDrawBoundingBox
enabledDebugDraw
Methods
hasEventListener
Checks whether the EventTarget object has any callback registered for a specific type of event.
Parameters
type
String The type of event.
on
Register an callback of a specific event type on the EventTarget.
This type of event should be triggered via emit
.
Parameters
Examples
eventTarget.on('fire', function () {
cc.log("fire in the hole");
}, node);
off
Removes the listeners previously registered with the same type, callback, target and or useCapture,
if only type is passed as parameter, all listeners registered with that type will be removed.
Parameters
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 removed
Examples
var callback = eventTarget.on('fire', function () {
cc.log("fire in the hole");
}, target);
eventTarget.off('fire', callback, target);
eventTarget.off('fire');
targetOff
Removes all callbacks previously registered with the same target (passed as parameter).
This is not for removing all listeners in the current event target,
and this is not for removing all listeners the target parameter have registered.
It's only for removing all listeners (callback and target couple) registered on the current event target by the target parameter.
Parameters
target
Object The target to be searched for all related listeners
once
Register an callback of a specific event type on the EventTarget,
the callback will remove itself after the first time it is triggered.
Parameters
Examples
eventTarget.once('fire', function () {
cc.log("this is the callback and will be invoked only once");
}, node);
dispatchEvent
Send an event with the event object.
Parameters