Egret之龙骨事件

简介:

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

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

wKioL1nD1IXgJRMQAAHd7ukr8L0794.png-wh_50

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


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

wKioL1nD1R6xpuLfAABJAoyS4JI935.png-wh_50


核心代码如下::

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
   /**
         * 展示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);
         }

结果:

wKioL1nD1zDjUEBSAAA7Cle7uyY427.png-wh_50

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

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



添加音乐事件

wKiom1nD2HeiIe1KAAA2RzqiOWI291.png-wh_50


代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
   /**
         * 展示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);
         }

结果:

wKioL1nD2VXzchVwAAAsG_PNctk426.png-wh_50

关键:

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
















本文转自Aonaufly51CTO博客,原文链接:http://blog.51cto.com/aonaufly/1967646 ,如需转载请自行联系原作者




相关文章
|
16天前
|
开发者
移动端 click 事件、touch 事件、tap 事件的区别
移动端 click 事件、touch 事件、tap 事件的区别
15 1
|
17天前
移动端click事件、touch事件、tap事件的区别
移动端click事件、touch事件、tap事件的区别
16 0
|
3月前
dragonBones.CCFactory.getInstance()导致的dragonBones突然不播放
dragonBones.CCFactory.getInstance()导致的dragonBones突然不播放
16 0
|
4月前
|
API
drag事件
drag事件
42 0
|
5月前
|
JavaScript 前端开发 测试技术
Egret Wing使用总结
Egret Wing使用总结
44 0
|
测试技术
egret createchild,childrencreate与addtostage比较
egret createchild,childrencreate与addtostage比较
|
图形学
Unity 动态加载Animator Event 事件
搬迁原来博客海澜CSDN 前一阵子频繁更改模型,总是手动添加动画事件 animator events一直比较麻烦,我就想能不能动态的生成对应的动画事件呢,然后找了一些资料,试了下感觉还不错,分享给大家,欢迎大家留言交流~需要注意的是修改后的动画事件重新动态加载后依然保留,猜测注册修改的是元数据,除非注销或者程序停止才能恢复。
1893 0