1. 程式人生 > >Egret之龍骨事件

Egret之龍骨事件

egret 龍骨 龍骨事件

首先來上龍骨的自定義事件:

1,在動畫制作中 , 選擇一個動畫 , 選中事件層加一個關鍵幀

技術分享

可以看到我在第11幀添加了一個關鍵幀


2,在屬性面板中添加一個自定義事件

技術分享


核心代碼如下::

  /**
        * 展示Sheep特效
        */
        private showRoleWing(wingId: number): void {
            this.egretFactory = tools.DragonBoneTools.Instance.createEff2New(
                "Sheep_Ani_ske_json",
                "Sheep_Ani_tex_json",
                "Sheep_Ani_tex_png",
                );
            this.eff_robot = this.egretFactory.buildArmatureDisplay("Armature");
            this.addChild(this.eff_robot);
            this.eff_robot.animation.play("goat_eat_anim",0);
            this.eff_robot.x = 200;
            this.eff_robot.y = 450;
            this.eff_robot.armature.addEventListener( dragonBones.AnimationEvent.START, this.startPlay,this);
            this.eff_robot.armature.addEventListener( dragonBones.AnimationEvent.LOOP_COMPLETE, this.loop_com,this);
            this.eff_robot.armature.addEventListener( dragonBones.FrameEvent.ANIMATION_FRAME_EVENT, this.frame_event,this);
             //this.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.onTouch,this);
        }
        private startPlay(evt:dragonBones.ArmatureEvent)
        {
            console.log( "動畫播放開始");
        }
        private loop_com(evt:dragonBones.ArmatureEvent)
        {
            console.log( "動畫播放完一輪完成!");
        }
        private frame_event(evt:dragonBones.FrameEvent)
        {
            console.log( " 播放到了一個關鍵幀! 幀標簽為:",evt.frameLabel);
        }

結果:

技術分享

關鍵: this.eff_robot.armature.addEventListener( dragonBones.FrameEvent.ANIMATION_FRAME_EVENT, this.frame_event,this);

當我們在DragonBones中加入了幀事件事 , 這個就會觸發。



添加音樂事件

技術分享


代碼:

  /**
        * 展示Sheep特效
        */
        private showRoleWing(wingId: number): void {
            this.egretFactory = tools.DragonBoneTools.Instance.createEff2New(
                "Sheep_Ani_ske_json",
                "Sheep_Ani_tex_json",
                "Sheep_Ani_tex_png",
                );
            this.eff_robot = this.egretFactory.buildArmatureDisplay("Armature");
            this.addChild(this.eff_robot);
            
            this.eff_robot.x = 200;
            this.eff_robot.y = 450;
            this.eff_robot.armature.addEventListener( dragonBones.AnimationEvent.START, this.startPlay,this);
            this.eff_robot.armature.addEventListener( dragonBones.AnimationEvent.LOOP_COMPLETE, this.loop_com,this);
            this.eff_robot.armature.addEventListener( dragonBones.FrameEvent.ANIMATION_FRAME_EVENT, this.frame_event,this);
            dragonBones.SoundEventManager.getInstance().addEventListener( dragonBones.SoundEvent.SOUND, this.sound_event,this);
             //this.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.onTouch,this);
             this.eff_robot.animation.play("goat_eat_anim",0);
        }
        private startPlay(evt:dragonBones.ArmatureEvent)
        {
            console.log("動畫播放開始");
        }
        private loop_com(evt:dragonBones.ArmatureEvent)
        {
            console.log( "動畫播放完一輪完成!");
        }
        private frame_event(evt:dragonBones.FrameEvent)
        {
            console.log( " 播放到了一個關鍵幀! 幀標簽為:",evt.frameLabel);
        }
        private sound_event(evt:dragonBones.SoundEvent)
        {
            console.log( "音的值為:",evt.sound);
        }

結果:

技術分享

關鍵:

dragonBones.SoundEventManager.getInstance().addEventListener( dragonBones.SoundEvent.SOUND, this.sound_event,this);

本文出自 “Better_Power_Wisdom” 博客,請務必保留此出處http://aonaufly.blog.51cto.com/3554853/1967646

Egret之龍骨事件