StartHUD.js 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. },
  5. start : function () {
  6. // this.startNetGame();
  7. },
  8. onLoad : function () {
  9. // this.setClickOnListener();
  10. this.GameStates = cc.find("Canvas").getComponent("GameStates");
  11. },
  12. setClickOnListener : function (callBack) {
  13. // var scene = cc.director.getScene();
  14. //
  15. // if (scene.name == "camera_ai") {
  16. // var HeroControlScript = cc.find("Hero").getComponent("HeroControl");
  17. // var Rivel = cc.find("Rivel");
  18. // var RivelControlScript = Rivel.getComponent("HeroControl");
  19. // HeroControlScript.EnableHeroMoving(true);
  20. // RivelControlScript.EnableHeroMoving(true);
  21. // HeroControlScript.readyRun();
  22. // RivelControlScript.readyRun();
  23. // var HeroPlayer = null;
  24. // if(cc.find('Hero').getChildByName('Player')!=null){
  25. // HeroPlayer = cc.find('Hero').getChildByName('Player');
  26. // }
  27. // //“我”头上的箭头,在我开始游戏的时候会摧毁掉。
  28. // if (HeroPlayer.getChildByName('MyArrow') != null) {
  29. // HeroPlayer.getChildByName('MyArrow').destroy();
  30. // }
  31. // //点击开始播放鸣枪声
  32. // if (HeroPlayer.getChildByName('MyAudio') != null) {
  33. // var AudioControlScript = HeroPlayer.getChildByName('MyAudio').getComponent("AudioControl");
  34. // var AudioSource = AudioControlScript.getAudioSourceByName("StartGun");
  35. // AudioSource.play();
  36. // }
  37. // this.node.destroy();
  38. // return;
  39. // }
  40. // this.startNetGame();
  41. this.StartToRun();
  42. },
  43. startNetGame : function () {
  44. if(cc.find('Canvas').getComponent('GameStates').BWaitingToConnect) return;
  45. this.node.getChildByName('label').getComponent(cc.Label).string='Waiting for Match';
  46. cc.find('Canvas').getComponent('GameStates').BWaitingToConnect = !cc.find('Canvas').getComponent('GameStates').BWaitingToConnect;
  47. if(cc.find('Canvas').getComponent('GameStates').bReadyToRun)
  48. {
  49. this.StartToRun();
  50. }
  51. else {
  52. cc.find('Canvas').getComponent('GameStates').bReadyToRun = !cc.find('Canvas').getComponent('GameStates').bReadyToRun;
  53. }
  54. var Hero = cc.find("Hero");
  55. var NetworkSocket = Hero.getComponent('NetworkSocket');
  56. var data = {FunctionName:'ReadyToRun'};
  57. NetworkSocket.sendSyncData(JSON.stringify(data));
  58. },
  59. StartToRun:function()
  60. {
  61. cc.find('Canvas').getComponent('GameStates').BStartGame = !cc.find('Canvas').getComponent('GameStates').BStartGame;
  62. var self = this;
  63. var Hero = cc.find("Hero");
  64. // var Rivel = cc.find("Rivel");
  65. var HeroControlScript = Hero.getComponent("HeroControl");
  66. // var RivelControlScript = Rivel.getComponent("HeroControl");
  67. HeroControlScript.playAudioByName('StartGun');//项目开始时哨声
  68. Hero.getChildByName("Player").getComponent("Charactor").setOnTouchListener(event);
  69. // Rivel.getChildByName("Player").getComponent("Charactor").setOnTouchListener(event);
  70. HeroControlScript.EnableHeroMoving(true);
  71. // RivelControlScript.EnableHeroMoving(true);
  72. this.schedule(function()
  73. {
  74. HeroControlScript.InitialPositionY = HeroControlScript.node.getPositionY();
  75. // RivelControlScript.InitialPositionY = RivelControlScript.node.getPositionY();
  76. self.node.destroy();
  77. }, 0.01, 0);
  78. },
  79. });