CocosCreator之KUOKUO带你做疯狂炮台(2)

本次引擎2.0.5

编辑工具VSCode

本系列默认你不是特别小白,console.log(滑稽)

第二部分:BOSS挨打与次数显示。

好,我们第一部分刚做出了无限子弹,这一次我们找个BOSS(就是挨打的)

单色节点配标签(忽然发现我好爱单色节点)

然后给Boss加上碰撞盒(不是物理组件里面的哦)

预制体子弹也加上;

然后来到我们的碰撞分组管理器:

项目->项目设置;

然后我们给分个类:

我们让子弹跟boss可以产生碰撞,然后改一下分组:

好了,让我们在boss上挂个监本,写碰撞函数:

cc.Class({
    extends: cc.Component,

    properties: {
        // 显示剩余生命
        hp_label : cc.Label,
    },

    onLoad () {
        // 开启碰撞检测
        var manager = cc.director.getCollisionManager();
        manager.enabled = true;
        // 初始hp
        this.hp = 100;
    },

    // 当碰撞产生的时候调用
    onCollisionEnter (other, self) {
        // 子弹节点回收
        other.node.stopAllActions();
        other.node.parent.getComponent('bulletManager').bulletPool.put(other.node);
        // hp - 1,+''是为了转化字符串
        this.hp -= 1;
        this.hp_label.string = this.hp + '';
    },
});

怎么样,是不是完成了呢!

O(∩_∩)O~~

猜你喜欢

转载自blog.csdn.net/kuokuo666/article/details/84196457