55 lines
2.2 KiB
TypeScript
55 lines
2.2 KiB
TypeScript
|
|
// Learn TypeScript:
|
||
|
|
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
|
||
|
|
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
|
||
|
|
// Learn Attribute:
|
||
|
|
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
|
||
|
|
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
|
||
|
|
// Learn life-cycle callbacks:
|
||
|
|
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
|
||
|
|
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
|
||
|
|
|
||
|
|
const {ccclass, property} = cc._decorator;
|
||
|
|
import GameData from "./GameData";
|
||
|
|
|
||
|
|
@ccclass
|
||
|
|
export default class NewClass extends cc.Component {
|
||
|
|
|
||
|
|
@property(cc.Node)
|
||
|
|
ship1Selector: cc.Node = null;
|
||
|
|
|
||
|
|
@property(cc.Node)
|
||
|
|
ship2Selector: cc.Node = null;
|
||
|
|
|
||
|
|
@property(cc.Node)
|
||
|
|
ship3Selector: cc.Node = null;
|
||
|
|
|
||
|
|
@property(cc.SpriteFrame)
|
||
|
|
selectFrame: cc.SpriteFrame = null;
|
||
|
|
|
||
|
|
@property(cc.SpriteFrame)
|
||
|
|
selectedFrame: cc.SpriteFrame = null;
|
||
|
|
|
||
|
|
onLoad () {
|
||
|
|
if(GameData.instance.selectedShip === 1) {
|
||
|
|
this.ship1Selector.getComponent(cc.Sprite).spriteFrame = this.selectedFrame;
|
||
|
|
} else if(GameData.instance.selectedShip === 2) {
|
||
|
|
this.ship2Selector.getComponent(cc.Sprite).spriteFrame = this.selectedFrame;
|
||
|
|
} else if(GameData.instance.selectedShip === 3) {
|
||
|
|
this.ship3Selector.getComponent(cc.Sprite).spriteFrame = this.selectedFrame;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
update (dt) {
|
||
|
|
this.ship1Selector.getComponent(cc.Sprite).spriteFrame = this.selectFrame;
|
||
|
|
this.ship2Selector.getComponent(cc.Sprite).spriteFrame = this.selectFrame;
|
||
|
|
this.ship3Selector.getComponent(cc.Sprite).spriteFrame = this.selectFrame;
|
||
|
|
if(GameData.instance.selectedShip === 1) {
|
||
|
|
this.ship1Selector.getComponent(cc.Sprite).spriteFrame = this.selectedFrame;
|
||
|
|
} else if(GameData.instance.selectedShip === 2) {
|
||
|
|
this.ship2Selector.getComponent(cc.Sprite).spriteFrame = this.selectedFrame;
|
||
|
|
} else if(GameData.instance.selectedShip === 3) {
|
||
|
|
this.ship3Selector.getComponent(cc.Sprite).spriteFrame = this.selectedFrame;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|