import RoleRender from "../Game/RoleRender"; const {ccclass, property} = cc._decorator; @ccclass export default class Matching extends cc.Component { waitingPositions:cc.Vec2[] = new Array(); waitingIndex:number = 0; onLoad(){ this.node.children.forEach((node:cc.Node)=>{ if(node.name=='RoleNode'){ this.waitingPositions.push(node.position); } }); this.match(); } match(){ if(this.waitingIndex<4){ let roleNode = cc.instantiate(window.resource.pf_Role); roleNode.setScale(0.6); roleNode.setPosition(this.waitingPositions.shift().sub(cc.v2(0,70))); roleNode.addComponent(RoleRender).index = this.waitingIndex; this.node.addChild(roleNode); this.waitingIndex++; setTimeout(() => { this.match(); }, 300); }else{ this.node.getChildByName('Title').removeComponent(cc.Animation); this.node.getChildByName('Title').getComponent(cc.Label).string = '匹配成功'; setTimeout(() => { this.node.active = false; window.controller.startGame(); }, 1000); } } }