Matching.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import RoleRender from "../Game/RoleRender";
  2. const {ccclass, property} = cc._decorator;
  3. @ccclass
  4. export default class Matching extends cc.Component {
  5. waitingPositions:cc.Vec2[] = new Array();
  6. waitingIndex:number = 0;
  7. onLoad(){
  8. this.node.children.forEach((node:cc.Node)=>{
  9. if(node.name=='RoleNode'){
  10. this.waitingPositions.push(node.position);
  11. }
  12. });
  13. this.match();
  14. }
  15. match(){
  16. if(this.waitingIndex<4){
  17. let roleNode = cc.instantiate(window.resource.pf_Role);
  18. roleNode.setScale(0.6);
  19. roleNode.setPosition(this.waitingPositions.shift().sub(cc.v2(0,70)));
  20. roleNode.addComponent(RoleRender).index = this.waitingIndex;
  21. this.node.addChild(roleNode);
  22. this.waitingIndex++;
  23. setTimeout(() => {
  24. this.match();
  25. }, 300);
  26. }else{
  27. this.node.getChildByName('Title').removeComponent(cc.Animation);
  28. this.node.getChildByName('Title').getComponent(cc.Label).string = '匹配成功';
  29. setTimeout(() => {
  30. this.node.active = false;
  31. window.controller.startGame();
  32. }, 1000);
  33. }
  34. }
  35. }