Egret之龙骨事件
admin
2023-02-17 16:00:02
0

首先来上龙骨的自定义事件:

1,在动画制作中 , 选择一个动画  , 选中事件层加一个关键帧

Egret之龙骨事件

可以看到我在第11帧添加了一个关键帧


2,在属性面板中添加一个自定义事件

Egret之龙骨事件


核心代码如下::

  /**
        * 展示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);
        }

结果:

Egret之龙骨事件

关键: this.eff_robot.armature.addEventListener( dragonBones.FrameEvent.ANIMATION_FRAME_EVENT, this.frame_event,this);

当我们在DragonBones中加入了帧事件事 , 这个就会触发。



添加音乐事件

Egret之龙骨事件


代码:

  /**
        * 展示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);
        }

结果:

Egret之龙骨事件

关键:

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






更新事件

this._zhujueArm.addEventListener(dragonBones.EventObject.COMPLETE,this.comAttack,this);
this._zhujueArm.addEventListener(dragonBones.EventObject.FRAME_EVENT,this.aniFrame,this);


/**
      * boss动作帧事件
      */ 
     private aniFrame(e:dragonBones.EgretEvent):void
     {
         if(e.data.name=="A")
         {
             this.attackCb();
         }
     }


上一篇:Egret之JSZip基础

下一篇:Egret之龙骨换装

相关内容

热门资讯

菲律宾,没有以色列的命,得了以... 菲律宾,马尼拉。美国国务卿鲁比奥来了。菲律宾期盼已久的“救星”来了。菲律宾认为的“阳光”来了。从机场...
服务器盛会东莞启幕,松山湖软硬... 7月23日至24日,“智算筑基 融链共赢——2026年服务器产业供需对接活动”在东莞举行。作为系列配...
面向6G通信、高端安检、精准医... 太赫兹作为“电磁波段最后一块未开垦之地”,近年在超快光电子、低尺度半导体技术的推动下,逐步从实验室走...
获得全球最高奖项的中国数学家,... 一个喜欢玩梗的二次元大佬,竟然站上了数学界最高荣誉的领奖台。他就是今年的菲尔兹奖得主之一,邓煜。另一...
单向空间杭州旗舰店8年后谢幕,... 去年12月,单向空间杭州乐堤港店员工回应闭店谣言,称“没有收到任何闭店通知”。不到一年,停止营业的消...
带娃家长刷不到下铺,算法不该把... 据新华社的报道,一位宝妈带4岁娃要从昭通去杭州南,在12306上购票时反复被分到上铺,一天内取消三次...
安徽一高标准农田电机出水异常,... 近日,安徽省淮北市濉溪县百善镇丁楼村村民向《都市现场》爆料称:村里2023年建成的高标准农田配套电机...
河北一演唱会音响“翻车”,人声... 近日,来自北京的庞女士向都市现场记者反映,她7月11日在河北唐山观看“青春超燃巨星演唱会”时遭遇了极...
尺素金声|中国经济“失速论”站... 一季度GDP同比增长5.0%、二季度增长4.3%、上半年增长4.7%,2026年中国经济半年报发布后...
NVIDIA最深的护城河要凉!... 7月24日消息,AMD在Advancing AI预简报会上表示,CUDA已不再是外界想象中的那条护城...