ColorBar.js 1.6 KB

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