You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.4 KiB
TypeScript

const {ccclass, property} = cc._decorator;
import {gameMY} from './gameModule';
// const eventTarget = new cc.EventTarget();
enum columnState {
}
@ccclass
export class columnControl extends cc.Component {
// @property({type: gameMY}) 這句不行
// public gameModule: gameMY | null = null;
@property((cc.Node))
gameModule: cc.Node;
private nowAction = null;
private columnItem: Array<number> = [];
private itemList:Array<number>;
private gameModuleScript;
actionSet = {
"stayPosition": cc.moveTo(0, new cc.Vec2(0, 240)),
"rollingUp2Button": cc.sequence(cc.moveTo(0, new cc.Vec2(0, 240)), cc.moveBy(1.5, new cc.Vec2(0, -240))),
};
protected onLoad () {
this.gameModuleScript = this.gameModule.getComponent('gameMY');
}
protected start () {
cc.log("this columnControl start");
this.itemList = Object.values(this.gameModuleScript.itemNameMapping);
for(let i=0;i<this.node.childrenCount;i++){
let a = this.itemList[Math.floor(Math.random() * 12)];
this.columnItem.unshift( a );
this.node.children[i].getComponent(cc.Sprite).spriteFrame = this.gameModuleScript.item_spriteFrame[a]
}
this.nowAction = this.node.runAction(this.actionSet["stayPosition"]);
}
protected update (dt) {
if(this.nowAction.isDone() == true) {
let a = this.itemList[Math.floor(Math.random() * 12)];
this.columnItem.unshift( a );
this.columnItem.pop();
//換圖
for(let i=0;i<this.columnItem.length;i++){
this.node.children[i].getComponent(cc.Sprite).spriteFrame = this.gameModuleScript.item_spriteFrame[this.columnItem[i]]
}
//移動位置
this.nowAction = this.node.runAction(this.actionSet["rollingUp2Button"]);
}else{
}
}
}
// 用 tween 做動畫
// cc.tween(b)
// .to(1, { position: cc.v2(100, 0), rotation: 360 })
// .to(1, { position: cc.v2(0, 0), rotation: 0 })
// // .to(1, { scale: 2 })
// .start()
// 用 Action 做動畫
// var seq = cc.sequence(cc.moveBy(1.5, cc.Vec2(100, 50)), cc.moveBy(1.5, cc.Vec2(-100, -50)));
// b.runAction(this.seq)
// c.runAction(this.seq) // 失敗 seq 不能一次賦予兩個物件一樣動作
// this.bigFrameString.node.runAction(seq)