const GameModule = require("../utils/GameModule"); const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey; cc.Class({ extends: cc.Component, properties: { zIndex: { default: 0, notify(oldValue) { //减少无效赋值 if (oldValue === this.zIndex) { return; } this.node.zIndex = this.zIndex; } }, }, // LIFE-CYCLE CALLBACKS: onLoad () { this.node.zIndex = this.zIndex; this._playing = false; this.colorBarSkeletion = this.node.getComponent(sp.Skeleton); let animations = this.colorBarSkeletion.skeletonData.getRuntimeData(true).animations; this.animationList = animations.map(animation => animation.name); this.colorBarSkeletion.node.active = false; this.colorBarSkeletion.paused = true; this.colorBarSkeletion.setCompleteListener(() => { this.colorBarSkeletion.node.active = false; this.colorBarSkeletion.paused = true; this._playing = false; }); //isFocus为true为强制覆盖动画 GameEvent.on(GameNotificationKey.PlaySuccessAnimation, this, (isFocus) => { if (this._playing && !isFocus) { return; } this.colorBarSkeletion.node.active = true; this.colorBarSkeletion.paused = false; this._playing = true; let random = Math.floor(Math.random() * this.animationList.length); this.colorBarSkeletion.setAnimation(0, this.animationList[random], false); }); }, onDestroy() { GameEvent.off(GameNotificationKey.PlaySuccessAnimation, this) }, start () { }, });