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.

155 lines
4.1 KiB
TypeScript

const {ccclass, property} = cc._decorator;
import {gameMY} from './gameModule';
import {columnControl} from './columnControl';
@ccclass
export default class NewClass extends cc.Component {
@property((cc.Node))
gameModule: cc.Node = null;
@property((cc.Node))
columnControl: cc.Node = null;
private secCounter: number = 0;
private fpsCount: number = 0;
private gameModuleScript;
private columnControlScript;
protected onLoad () {
cc.log("this is ee onLoad");
// 呼叫其他 script 的方法或資源
this.gameModuleScript = this.gameModule.getComponent('gameMY')
this.columnControlScript = this.columnControl.getComponent('columnControl')
}
protected onEnable(){
cc.log("this is ee onEnable");
}
protected start () {
cc.log("this is ee start");
this.secCounter = 0;
}
tempValue = true
protected update (dt) {
this.secCounter += dt;
this.fpsCount += 1;
// 測試 cc.resources.loadDir 載入時間 ==> 結論: 約需要 0.2~0.5秒
if(this.tempValue){
if(!(Object.keys(this.gameModuleScript.item_spriteFrame).length === 0)){
cc.log(" .loadDir Complete : " + this.secCounter)
this.tempValue = false
}
}
if(this.secCounter >= 5) {
cc.log("engineer Function Update : " + this.fpsCount)
this.secCounter = 0
this.fpsCount = 0
}
}
protected onDisable(): void {
cc.log("this is ee onDisable")
}
unitTest1():void {
this.gameModule.emit('Bob', 'unitTest1 Success')
}
disableColumn():void {
// this.node.active = !this.node.active;
this.columnControl.active = !this.columnControl.active;
}
unitTest3():void {
// @ts-ignore
this.itemList = Object.values(this.gameModuleScript.itemNameMapping)
for(let i=0;i<this.columnControl.childrenCount;i++){
let a = this.itemList[Math.floor(Math.random() * 12)];
this.columnControlScript.columnItem.pop( a );
this.columnControlScript.columnItem.unshift( a );
let c = this.gameModuleScript.item_spriteFrame[a]
this.columnControl.children[i].getComponent(cc.Sprite).spriteFrame = c
}
}
test4():void {
this.node.getChildByName('UT4').y += 100;
cc.log("markA")
}
tempColumnState:any;
test5():void {
if(this.columnControlScript.nowState == 99){
this.columnControlScript.nowState = this.tempColumnState;
}else{
this.tempColumnState = this.columnControlScript.nowState;
this.columnControlScript.nowState = 99;
}
}
}
//
//
// 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))),
// };
// 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)