StartHUD.js 3.5 KB

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