ColorBar.js 1.7 KB

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