const DWTool = require("../utils/DWTool"); cc.Class({ extends: cc.Component, properties: { itemSprite: cc.Sprite, selectedSprite: cc.Sprite, }, // LIFE-CYCLE CALLBACKS: onLoad () { GameEvent.on('StoreDiamondSelect', this, (index) => { this.selectedSprite.node.active = this._index == index; }); }, init(index) { this._index = index; this.node.on(cc.Node.EventType.TOUCH_END, _.debounce(() => { GameEvent.fire('StoreDiamondSelect', this._index); }, 500, true), this); let imageIndex = index + 1; DWTool.loadResSpriteFrame(`./textures/store/store_diamond_${imageIndex}`) .then((spriteFrame) => { this.itemSprite.spriteFrame = spriteFrame; }); }, start () { }, onDestroy() { GameEvent.off('StoreDiamondSelect', this); } // update (dt) {}, });