最近搜索

第22讲 添加游戏音乐和音效

浏览:547
管理员 2021-08-24 05:34

把音乐挺进项目,game代码中声明 audio  ,播放音乐

image.png

        audio_bgm:cc.AudioClip,

                cc.audioEngine.playMusic(this.audio_bgm,true);
                         
        cc.audioEngine.setMusicVolume(0.5);




播放 换成play,使用playmusic 播放击中音乐后,背景音乐就停止了

        cc.audioEngine.play(this.audio_bgm,true,0.5);



英雄死亡和上面一样

cc.Class({
    extends: cc.Component,
    properties: {
        audio_hero_die:cc.AudioClip,
    },
    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 ;//游戏结束 
        game.isBgMove = false;
        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;
            game.game_over();
            cc.audioEngine.play(this.audio_hero_die,false,0.5);
        }.bind(this);
    }
});


联系站长

站长微信:xiaomao0055

站长QQ:14496453