FirstStep

第一步讓全部盤面都轉起來。
This commit is contained in:
2022-10-25 22:32:13 +08:00
parent b20e00dbda
commit 45dc240075
63 changed files with 3214 additions and 2622 deletions
+92
View File
@@ -0,0 +1,92 @@
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)
+10
View File
@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "2bf4a2ce-1d32-4008-9c08-fa2bcd9b6ee3",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
+87
View File
@@ -0,0 +1,87 @@
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;
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;
// 測試 cc.resources.loadDir 載入時間 ==> 結論: 約需要 0.2~0.5秒
if(this.tempValue){
if(!(Object.keys(this.gameModuleScript.item_spriteFrame).length === 0)){
cc.log(" empty to full : " + this.secCounter)
this.tempValue = false
}
}
if(this.secCounter >= 5) {
cc.log("engineer Function Update : " + this.secCounter)
this.secCounter = 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.push( a );
let c = this.gameModuleScript.item_spriteFrame[a]
this.columnControl.children[i].getComponent(cc.Sprite).spriteFrame = c
}
}
}
+10
View File
@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "1edd79f4-2d40-469c-b8ed-d1112d2d4159",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
+122 -10
View File
@@ -5,24 +5,136 @@
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
const {ccclass, property} = cc._decorator;
const {ccclass, property, } = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
@property(cc.Label)
label: cc.Label = null;
enum moduleState {
"INIT",
};
@ccclass("gameMY")
export class gameMY extends cc.Component {
@property
text: string = 'hello';
columnCount = 5;
// LIFE-CYCLE CALLBACKS:
@property
itemSize = 240;
// onLoad () {}
@property(cc.Label)
betString: cc.Label = null;
start () {
@property(cc.Label)
bigFrameString: cc.Label = null;
@property(cc.Label)
balanceString: cc.Label = null;
@property({type: cc.Prefab})
columnPrefab: cc.Prefab | null = null;
@property(cc.Node)
slotBoard: cc.Node = null;
private betNumber: number;
private balanceNumber: number;
private bigFrameNumber: number;
// item 圖片資源存放區
itemNameMapping = {
'item_01':1, 'item_02':2, 'item_03':3, 'item_04':4, 'item_9':5,
'item_10':6, 'item_j':7, 'item_k':8, 'item_q':9, 'item_a':10,
'item_scatter':51, 'item_wild':52
} as const;
item_spriteFrame = {};
itemBlur_spriteFrame = {};
init_Complete:boolean = false
protected onLoad () {
this.unitTestInit(); // for engineer use
// 讀取 item 圖片資源
cc.resources.loadDir('item',cc.SpriteFrame, (err: any, sF) => {
sF.forEach( (eachSpriteFrame)=>{
this.item_spriteFrame[ this.itemNameMapping[eachSpriteFrame.name] ] = eachSpriteFrame
})
} );
cc.resources.loadDir('item_blur',cc.SpriteFrame, (err: any, sF) => {
sF.forEach( (eachSpriteFrame)=>{
this.itemBlur_spriteFrame[ this.itemNameMapping[eachSpriteFrame.name] ] = eachSpriteFrame
})
} );
}
// update (dt) {}
protected start () {
this.betNumber = 50;
this.slotBoard.addChild( cc.instantiate(this.columnPrefab) )
this.slotBoard.addChild( cc.instantiate(this.columnPrefab) )
this.slotBoard.addChild( cc.instantiate(this.columnPrefab) )
this.slotBoard.addChild( cc.instantiate(this.columnPrefab) )
}
protected update (dt) {
if(!this.init_Complete){
// 完成圖片載入再啟動 column
if((Object.keys(this.item_spriteFrame).length === 12)){
for(let i=0;i<=5;i++){
this.slotBoard.children[i].getComponent('columnControl').gameModule = this.node;
this.slotBoard.children[i].active = true;
this.init_Complete=true;
}
}
}
}
onBetBtnClick(e: cc.Event.EventTouch): void {
// let a = e.getCurrentTarget().name
// cc.log(a)
if(e.getCurrentTarget().name == 'btn_plus'){
this.betNumber += 50;
}
else{
this.betNumber -= 50;
}
this.betString.string = "" + this.betNumber
}
onSpinBtnClick():void {
cc.log("nothing");
}
unitTestInit():void {
// for unitTest 1
this.node.on('Bob', (arg1)=>{
cc.log("columnControl Recieve Bob say " + arg1)
}, this)
}
}