ColorBar.js 1.6 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. this.colorBarSkeletion.node.active = false;
  22. this.colorBarSkeletion.paused = true;
  23. Global.GameEvent.on(GameNotificationKey.PlaySuccessAnimation, this, () => {
  24. if (this._playing) { return; }
  25. this.colorBarSkeletion.node.active = true;
  26. this.colorBarSkeletion.paused = false;
  27. this._playing = true;
  28. let animKeyArray = ['caidai1', 'caidai2'];
  29. let random = Math.floor(Math.random() * 2);
  30. this.colorBarSkeletion.setAnimation(0, animKeyArray[random], false);
  31. this.colorBarSkeletion.setCompleteListener(() => {
  32. this.colorBarSkeletion.node.active = false;
  33. this.colorBarSkeletion.paused = true;
  34. this._playing = false;
  35. });
  36. });
  37. },
  38. onDestroy() {
  39. Global.GameEvent.off(GameNotificationKey.PlaySuccessAnimation, this)
  40. },
  41. start () {
  42. },
  43. // update (dt) {},
  44. });