温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Egret之龙骨事件

发布时间:2020-07-30 11:36:35 来源:网络 阅读:2237 作者:Aonaufly 栏目:开发技术

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

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();
         }
     }


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI