import { _decorator, Component, Director, director, Node, UITransform } from 'cc'; import { StartGameUINode } from './StartGameUINode'; import { CharacterType, GamerNode } from './GamerNode'; import { BaseSprite } from '../GlobalScript/CommonComponent/BaseSprite'; import { NpkImage } from '../Tool/NPKImage'; import { AnimationNode } from '../GlobalScript/Animation/AnimationNode'; import { BaseButton, BaseButtonState } from '../GlobalScript/CommonComponent/BaseButton'; import { DiceButtonNode } from './DiceButtonNode'; const { ccclass } = _decorator; @ccclass('UIRoot') export class UIRoot extends Component { /// 等待玩家 private awaitGamerNode: Node; /// 玩家一 private gamerOne: GamerNode; /// 玩家二 private gamerTwo: GamerNode; /// 玩家三 private gamerThree: GamerNode; /// 投骰子按钮 private diceButton: DiceButtonNode; /// 初始化开始游戏界面的UI initStartGameUI(){ const startGameUINode = new StartGameUINode(); startGameUINode.addComponent( UITransform).setContentSize(1067,600); this.node.addChild(startGameUINode); } /// 初始化游戏界面UI initGameUI(){ /// 初始化玩家UI this.initGamerUI(); this.initDiceButton(); this.initAwaitGamerUI(); } /// 初始化玩家UI initGamerUI(){ this.gamerOne = new GamerNode('玩家一') this.gamerOne.setPosition(0,-540); this.gamerOne.charchterType = CharacterType.JianHun; this.node.addChild( this.gamerOne ); this.gamerTwo = new GamerNode('') this.gamerTwo.setPosition(877,0); this.node.addChild( this.gamerTwo ); this.gamerThree = new GamerNode('') this.node.addChild( this.gamerThree ); this.initDiceButton(); } /// 初始化加载UI initAwaitGamerUI(){ const node = new Node(); node.setPosition(177.5,-244.5); this.node.addChild(node); const spr = node.addComponent( BaseSprite); spr.updateSpriteFrame(NpkImage.loading_loop,0); const ani = new AnimationNode('ani/loading_loop01.ani'); ani.setPosition(350,-110); node.addChild( ani ); this.awaitGamerNode = node; /// 2秒后 结束加载 this.scheduleOnce(()=>{ /// 这一帧结束之后销毁 director.once(Director.EVENT_END_FRAME,()=>{ // 销毁 this.awaitGamerNode.destroy(); }); /// 初始化开始倒计时 this.initCountFontAni(5); },2); } /// 初始化倒计时动画 initCountFontAni(index:number){ const ani = new AnimationNode('ani/dnf_quiz_' + index +'.ani',()=>{ director.once(Director.EVENT_END_FRAME,()=>{ ani.destroy(); }); if (index > 1){ this.initCountFontAni(index-1); }else{ this.diceButton.winButtonComponent.ButtonState = BaseButtonState.Normal; } }); ani.setPosition(420,-180); this.node.addChild( ani ); } /// 初始化投骰子按钮 initDiceButton(){ this.diceButton = new DiceButtonNode(); this.diceButton.setPosition(849,-453); this.node.addChild(this.diceButton); } start() { this.node.addComponent( UITransform ).setContentSize(1067,600); this.initStartGameUI(); } update(deltaTime: number) { } }