StoreDiamondItem.js 948 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const DWTool = require("../utils/DWTool");
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. itemSprite: cc.Sprite,
  6. selectedSprite: cc.Sprite,
  7. },
  8. // LIFE-CYCLE CALLBACKS:
  9. onLoad () {
  10. GameEvent.on('StoreDiamondSelect', this, (index) => {
  11. this.selectedSprite.node.active = this._index == index;
  12. });
  13. },
  14. init(index) {
  15. this._index = index;
  16. this.node.on(cc.Node.EventType.TOUCH_END, _.debounce(() => {
  17. GameEvent.fire('StoreDiamondSelect', this._index);
  18. }, 500, true), this);
  19. let imageIndex = index + 1;
  20. DWTool.loadResSpriteFrame(`./textures/store/store_diamond_${imageIndex}`)
  21. .then((spriteFrame) => {
  22. this.itemSprite.spriteFrame = spriteFrame;
  23. });
  24. },
  25. start () {
  26. },
  27. onDestroy() {
  28. GameEvent.off('StoreDiamondSelect', this);
  29. }
  30. // update (dt) {},
  31. });