首先来上龙骨的自定义事件:
1,在动画制作中 , 选择一个动画 , 选中事件层加一个关键帧
wKioL1nD1IXgJRMQAAHd7ukr8L0794.png-wh_50
可以看到我在第11帧添加了一个关键帧
2,在属性面板中添加一个自定义事件
wKioL1nD1R6xpuLfAABJAoyS4JI935.png-wh_50
核心代码如下::
/**
* 展示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
代码:
/**
* 展示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);
更新事件
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();
}
}
©著作权归作者所有:来自51CTO博客作者Aonaufly的原创作品,如需转载,请注明出处,否则将追究法律责任
Egret龙骨龙骨事件Egret
0
分享
收藏
上一篇:Egret之龙骨换装下一篇:Egret之MC逐帧动画
Aonaufly
318篇文章,88W+人气,11粉丝
致力于用技术改进研发质量和效率!
关注
提问和评论都可以,用心的回复会被更多人看到和认可
Ctrl+Enter 发布发布取消
猜你喜欢
Laya2.x之碰撞检测注意事项Laya2.x之Sprite3D更换贴图捕获input 文本框内容改变的事件(onchange,onblur,onPropertyChange比较)JavaScript模拟用户单击事件LIstView添加点击事件Qt学习之路(19): 事件(event)Cocos Creator开发中的按钮节点的事件处理方法收集整理的中国四大骨干网及ChinaNet详细介绍Qt学习之路(20): 事件接收与忽略Qt学习之路(22): 事件过滤器QT开发(十二)——QT事件处理机制Qt学习之路(23): 自定义事件编程猫开发《摘星星小怪物》游戏Egret制作Loading页面及分步加载资源教程Egret场景切换管理类切换和单例使用方法使用P2物理引擎制作物理小球搭建Websocket简易聊天室使用Egret插件压缩代码包体积,减少请求数量的实战教程Egret之龙骨卡槽(slot)换皮一个可以打开一个网页的Python程序0daybank
文章评论