Actgift.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. //
  6. actGiftFrames: {
  7. tooltip: '奖品大图',
  8. default: [],
  9. type: [cc.SpriteFrame]
  10. },
  11. actGiftSprite: cc.Sprite,
  12. actGiftLabel: cc.Label,
  13. zIndex: {
  14. default: 0,
  15. notify(oldValue) {
  16. //减少无效赋值
  17. if (oldValue === this.zIndex) {
  18. return;
  19. }
  20. this.node.zIndex = this.zIndex;
  21. }
  22. },
  23. },
  24. // LIFE-CYCLE CALLBACKS:
  25. onLoad () {
  26. this.giftMap = ['coin', 'diamond', 'ticket'];
  27. this.node.zIndex = this.zIndex;
  28. },
  29. init(type, showText, spriteFrame) {
  30. if (spriteFrame) {
  31. this.actGiftSprite.spriteFrame = spriteFrame;
  32. if (showText) {
  33. this.actGiftLabel.node.active = true;
  34. this.actGiftLabel.string = showText;
  35. } else {
  36. this.actGiftLabel.node.active = false;
  37. }
  38. } else {
  39. this.giftMap.forEach((value, index) => {
  40. if (type == value) {
  41. this.actGiftSprite.spriteFrame = this.actGiftFrames[index];
  42. if (showText) {
  43. this.actGiftLabel.node.active = true;
  44. this.actGiftLabel.string = showText;
  45. } else {
  46. this.actGiftLabel.node.active = false;
  47. }
  48. }
  49. })
  50. }
  51. },
  52. hideActGift() {
  53. this.node.destroy();
  54. },
  55. start () {
  56. },
  57. // update (dt) {},
  58. });