const {ccclass, property} = cc._decorator;
@ccclass
export default class db extends cc.Component {
@property({ type: dragonBones.ArmatureDisplay }) //龙骨动画属性 lihuidh: dragonBones.ArmatureDisplay = null;
bfzt: boolean = true;//申明一个立绘动画播放状态,默认为否(未播放完成); // LIFE-CYCLE CALLBACKS:
onLoad() { this.lihuidh.addEventListener(dragonBones.EventObject.LOOP_COMPLETE, this.donghua, this) //动画动画监听 // let slot1 = this.lihuidh.armature() as dragonBones.Armature; this.donghua() }
// start () {
// }
// update (dt) {
// } donghua() { //默认立绘动画播放 if (this.bfzt == true) { //如果立绘动画状态为播放 let t = JSON.parse(cc.sys.localStorage.getItem("guankalv"))//获取已解锁的关卡等级 if (t == 0 || t == null) { //如果关卡等级为0或关卡等级获取不到 this.lihuidh.playAnimation("idle_1_复制1", -1) //默认播放苏九名称为“idle_1_复制1”动画;参数格式:龙骨动画名称,循环设置:-1为采用龙骨文件设置,0为永久循环,大于0为循环次数; } else if (t == 1) {//如果关卡等级等于1 this.lihuidh.playAnimation("idle_1", -1) } this.bfzt = false;//设置播放状态为未播放; } } chequn() { let t = JSON.parse(cc.sys.localStorage.getItem("guankalv")) //获取关卡等级 let yuyan = cc.find("changzhu").getComponent("changzhu").yuyan //获取语言版本 if (t != null) { //如果关卡等级不等于没有 if (yuyan == 0) { //如果语言等于简体中文版 if (t == 0 || t == null) { if (this.bfzt == false) { //如果当前立绘动画未播放 this.bfzt = true //播放状态切换为正在播放; this.lihuidh.playAnimation("hit_2", 1)//播放指定名称的动画 // console.log(this.lihuidh.animationName) //输出当前播放的动画名称 } } else if (t == 1) {//如果关卡等级等于1 if (this.bfzt == false) { //如果当前立绘动画未播放 this.bfzt = true //播放状态切换为正在播放; this.lihuidh.playAnimation("hit_1", 1) } } } else if (yuyan > 0) { if (t == 0 || t == null) { if (this.bfzt == false) { this.bfzt = true this.lihuidh.playAnimation("hit_2", 1) } } else if (t == 1) { if (this.bfzt == false) { this.bfzt = true this.lihuidh.playAnimation("yanshi1", 1) } } } } } // moren() { // let t = JSON.parse(cc.sys.localStorage.getItem("guankalv")) // if (t == 0) { // if (this.bfzt == false) { // this.bfzt = true // this.lihuidh.playAnimation("idle_1_复制1", -1) // } // } else if (t == 1) { // if (this.bfzt == false) { // this.bfzt = true // this.lihuidh.playAnimation("idle_1", -1) // } // } // }}
<a class="attachment" href="/uploads/default/original/3X/3/e/3e21bc607798ca58a480b2351858521646967467.zip">龙骨动画播放代码笔记.zip</a> (1.3 KB)