学习笔记 9_Cocos Creator_ 碰撞

碰撞常用方法

  • onCollisionEnter
  • onCollisionStay
  • onCollisionExit
 // use this for initialization
    onLoad: function () {
        // 开启碰撞
        cc.director.getCollisionManager().enabled = true;
        // 显示碰撞区域
        cc.director.getCollisionManager().enabledDebugDraw = true;
        // cc.director.getCollisionManager().enabledDrawBoundingBox = true;

        this.touchingNumber = 0;
    },

    // 进入碰撞
    onCollisionEnter: function (other) {
        this.node.color = cc.Color.RED;
        this.touchingNumber ++;
    },

    // 碰撞中
    onCollisionStay: function (other) {
        // console.log('on collision stay');
    },

    // 退出碰撞
    onCollisionExit: function () {
        this.touchingNumber --;
        if (this.touchingNumber === 0) {
            this.node.color = cc.Color.WHITE;
        }
    }

你可能感兴趣的:(学习笔记 9_Cocos Creator_ 碰撞)