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之龙骨换装

相关内容

热门资讯

美伊维持停火,国际油价回落 新华社纽约5月5日电(记者刘亚南) 由于美国与伊朗停火状态持续,国际原油期货价格5日早盘显著走低后窄...
“AI是否会取代人类工作” 诺... 过去一年,“AI是否会取代人类工作”的讨论持续升温,相关研究报告、行业预判和真实案例不断刷屏,让职场...
每经热评丨豆包收费标志着国产A... 来源:滚动播报 (来源:千龙网) 春节的AI(人工智能)红包大战硝烟尚未散尽,豆包App Store...
北斗导航、无人机“显身手” 春... 眼下,产粮大省黑龙江的春耕工作正有序进行,在位于黑龙江鹤岗的普阳农场,水稻插秧工作从今天起全面启动,...
强词夺理!“中国不应获得最先进... ► 文 观察者网 熊超然 一边想赚中国市场的钱,一边却又“提防”中国科技的崛起,英伟达创始人兼首席执...
苹果iOS 27将允许用户选择... IT之家 5 月 6 日消息,彭博社记者马克 · 古尔曼今日报道称,苹果计划在今年秋季发布的 iOS...
鲁比奥:我们改了措辞,中俄别再... 【文/观察者网 齐倩】当地时间5月5日,美国国务卿鲁比奥在白宫简报会上称,美国提出了新的联合国决议,...
“南鼠北调”为攻击蒋万安?蓝营... 海峡导报综合报道 台北、新北地区近期分别发生“汉坦病毒”死亡及确诊个案,使鼠患问题引发关注。“青鸟”...
巴拿马外长喊话访华团:尊重中国... 【文/观察者网 柳白】据香港英文媒体《南华早报》报道,数名巴拿马议员组成的代表团抵达中国访问之际,巴...
华帝燃气灶自动熄火什么原因 原因:热敏针出现故障,检查灶眼,看中间的火焰能不能烧到探针,烧到探针才能定住火,在点火的时候,长按几...