cc.Class({ extends: cc.Component, properties: { cityPic: cc.Sprite, incomeSpeedLabel: cc.Label, indexLabel: cc.Label, stateSprite: cc.Sprite, incomeLayout: cc.Node, line: cc.Node, currentIndicator: cc.Node, }, // onLoad () {}, init(info, incomeSpeed) { this.info = info; this.indexLabel.string = info.id; switch (info.state) { case 1: this.statePath = 'selected'; this.picPath = info.picId + '_'; this.indexLabel.node.active = true; this.currentIndicator.active = true; break; case 2: this.statePath = 'unlocked'; this.picPath = info.picId + '_'; this.indexLabel.node.active = true; this.currentIndicator.active = false; break; default: this.statePath = 'lock'; this.picPath = info.picId; this.indexLabel.node.active = false; this.currentIndicator.active = false; break; } cc.loader.loadRes('./map/' + this.picPath, cc.SpriteFrame, (err, spriteFrame) => { this.cityPic.spriteFrame = spriteFrame; this.currentIndicator.y = this.cityPic.node.height / 2 - this.currentIndicator.height / 2; }); cc.loader.loadRes('./map/' + this.statePath, cc.SpriteFrame, (err, spriteFrame) => { this.stateSprite.spriteFrame = spriteFrame; }); if (incomeSpeed > 0) { this.incomeLayout.active = true; this.incomeSpeedLabel.string = `${incomeSpeed}/天`; } else { this.incomeLayout.active = false; } if (this.node.x === -110) { this.line.x = -60; this.line.scaleX = 1; } else { this.line.x = 60; this.line.scaleX = -1; } if (info.state == 2) { this.line.active = true; } else { this.line.active = false; } }, start() { }, setState(state) { switch (state) { case 1: this.statePath = 'selected'; this.picPath = this.info.picId + '_'; this.indexLabel.node.active = true; break; case 2: this.statePath = 'unlocked'; this.picPath = this.info.picId + '_'; this.indexLabel.node.active = true; break; default: this.statePath = 'lock'; this.picPath = this.info.picId; this.indexLabel.node.active = false; break; } let end = cc.callFunc(() => { cc.loader.loadRes('./map/' + this.statePath, cc.SpriteFrame, (err, spriteFrame) => { this.stateSprite.spriteFrame = spriteFrame; }); }); this.stateSprite.node.runAction(cc.sequence(cc.scaleTo(0.2, 0, 0), end, cc.scaleTo(0.2, 1, 1))); cc.loader.loadRes('./map/' + this.picPath, cc.SpriteFrame, (err, spriteFrame) => { this.cityPic.spriteFrame = spriteFrame; }); if (state == 2) { this.line.active = true; } else { this.line.active = false; } }, showFinishAnimation(cb) { this.line.active = true; this.line.getComponent('LineCtrl').showAnimation(() => { cc.loader.loadRes('./map/' + this.info.picId + '_', cc.SpriteFrame, (err, spriteFrame) => { this.cityPic.spriteFrame = spriteFrame; }); cc.loader.loadRes('./map/' + 'unlocked', cc.SpriteFrame, (err, spriteFrame) => { this.stateSprite.spriteFrame = spriteFrame; }); cb(); }); }, // update (dt) {}, });