Hi, im new to cocos creator. I’m trying to create a collision detection function that could give out different output when the target collided with different object. below are my code which i wrote base on the example from the Cocos tutorial site.
cc.Class({
extends: cc.Component,
properties: {
target:{
type: cc.Node,
default: null
},
sprite1:{
type: cc.Node,
default: null,
},
sprite2:{
type: cc.Node,
default: null,
},
sprite3:{
type: cc.Node,
default: null,
}
},
// LIFE-CYCLE CALLBACKS:
onLoad () {
cc.director.getCollisionManager().enabledDebugDraw=true;
cc.director.getCollisionManager().enabled=true;
cc.director.getCollisionManager().enabledDrawBoundingBox=true;
},
onCollsionEnter(sprite1, target){
console.log("sprite 1 hit");
},
onCollsionEnter(sprite2, target){
console.log("sprite 2 hit");
},
start () {
},
// update (dt) {},
});