最近搜索

第19讲 英雄战机和敌机的碰撞

浏览:470
管理员 2021-08-23 08:00

游戏的状态 也需要 重新 调整。 设计一个game_state,记录不同的状态,



新加一个分组hero  关联碰撞

image.png



给hero添加 碰撞组件  tag = 10

image.png


新建hero。js  关联到飞机上面  添加碰撞方法

image.png

cc.Class({
    extends: cc.Component,

    properties: {
    },
    onLoad() {
        this.init();
    },
    start() {
    },
    update(dt) {
    },
    init(){
        this.isDie = false;
        this.node.active = true;
        this.normal();
    },
    onCollisionEnter(other, self) {
        if (self.tag == 10&&this.isDie==false) {
            console.log("敌机碰到了,英雄");
            this.die();
        }
    },
    normal(){
        var anim = this.getComponent(cc.Animation);
        anim.play("hero_ animation_clip");
    },
    die(){
        this.isDie= true;
        game.game_state = 4 ;//游戏结束 
        var anim = this.getComponent(cc.Animation);
        anim.play("hero_die_animation_clip");
        anim.over = function () {
            //game.on_enemy_killed(this.node, 1);
            this.node.active = false;
        }.bind(this);
    }

});


给英雄飞机添加死亡动画(有over)  普通动画



修改game的代码 飞机死亡后 重新开始 需要初始化飞机。


image.png













联系站长

站长微信:xiaomao0055

站长QQ:14496453