ColorBar.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. const GameModule = require("../utils/GameModule");
  2. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. zIndex: {
  7. default: 0,
  8. notify(oldValue) {
  9. //减少无效赋值
  10. if (oldValue === this.zIndex) {
  11. return;
  12. }
  13. this.node.zIndex = this.zIndex;
  14. }
  15. },
  16. },
  17. // LIFE-CYCLE CALLBACKS:
  18. onLoad () {
  19. this.node.zIndex = this.zIndex;
  20. this._playing = false;
  21. this.colorBarSkeletion = this.node.getComponent(sp.Skeleton);
  22. let animations = this.colorBarSkeletion.skeletonData.getRuntimeData(true).animations;
  23. this.animationList = animations.map(animation => animation.name);
  24. this.colorBarSkeletion.node.active = false;
  25. this.colorBarSkeletion.paused = true;
  26. this.colorBarSkeletion.setCompleteListener(() => {
  27. this.colorBarSkeletion.node.active = false;
  28. this.colorBarSkeletion.paused = true;
  29. this._playing = false;
  30. });
  31. //isFocus为true为强制覆盖动画
  32. GameEvent.on(GameNotificationKey.PlaySuccessAnimation, this, (isFocus) => {
  33. if (this._playing && !isFocus) { return; }
  34. this.colorBarSkeletion.node.active = true;
  35. this.colorBarSkeletion.paused = false;
  36. this._playing = true;
  37. let random = Math.floor(Math.random() * this.animationList.length);
  38. this.colorBarSkeletion.setAnimation(0, this.animationList[random], false);
  39. });
  40. },
  41. onDestroy() {
  42. GameEvent.off(GameNotificationKey.PlaySuccessAnimation, this)
  43. },
  44. start () {
  45. },
  46. });