| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- cc.Class({
- extends: cc.Component,
- properties: {
- },
- start : function () {
- // this.startNetGame();
- },
- onLoad : function () {
-
- this.GameStates = cc.find("Canvas").getComponent("GameStates");
- },
- setClickOnListener : function (callBack) {
- var scene = cc.director.getScene();
- if (scene.name == "camera_ai") {
- var HeroControlScript = cc.find("Hero").getComponent("HeroControl");
- var Rivel = cc.find("Rivel");
- var RivelControlScript = Rivel.getComponent("HeroControl");
- HeroControlScript.EnableHeroMoving(true);
- RivelControlScript.EnableHeroMoving(true);
- HeroControlScript.readyRun();
- RivelControlScript.readyRun();
- var HeroPlayer = null;
- if(cc.find('Hero').getChildByName('Player')!=null){
- HeroPlayer = cc.find('Hero').getChildByName('Player');
- }
- //“我”头上的箭头,在我开始游戏的时候会摧毁掉。
- if (HeroPlayer.getChildByName('MyArrow') != null) {
- HeroPlayer.getChildByName('MyArrow').destroy();
- }
- //点击开始播放鸣枪声
- if (HeroPlayer.getChildByName('MyAudio') != null) {
- var AudioControlScript = HeroPlayer.getChildByName('MyAudio').getComponent("AudioControl");
- var AudioSource = AudioControlScript.getAudioSourceByName("StartGun");
- AudioSource.play();
- }
- this.node.destroy();
- return;
- }
- this.startNetGame();
- },
- startNetGame : function () {
- if(cc.find('Canvas').getComponent('GameStates').BWaitingToConnect) return;
- this.node.getChildByName('label').getComponent(cc.Label).string='Waiting for Match';
- cc.find('Canvas').getComponent('GameStates').BWaitingToConnect = !cc.find('Canvas').getComponent('GameStates').BWaitingToConnect;
- if(cc.find('Canvas').getComponent('GameStates').bReadyToRun)
- {
- this.StartToRun();
- }
- else {
- cc.find('Canvas').getComponent('GameStates').bReadyToRun = !cc.find('Canvas').getComponent('GameStates').bReadyToRun;
- }
- var Hero = cc.find("Hero");
- var NetworkSocket = Hero.getComponent('NetworkSocket');
- var data = {FunctionName:'ReadyToRun'};
- NetworkSocket.sendSyncData(JSON.stringify(data));
- },
- StartToRun:function()
- {
- cc.find('Canvas').getComponent('GameStates').BStartGame = !cc.find('Canvas').getComponent('GameStates').BStartGame;
- var self = this;
- var Hero = cc.find("Hero");
- var Rivel = cc.find("Rivel");
- var HeroControlScript = Hero.getComponent("HeroControl");
- var RivelControlScript = Rivel.getComponent("HeroControl");
- // HeroControlScript.playAudioByName('StartGun');//项目开始时哨声
- Hero.getChildByName("Player").getComponent("Charactor").setOnTouchListener(event);
- Rivel.getChildByName("Player").getComponent("Charactor").setOnTouchListener(event);
- HeroControlScript.EnableHeroMoving(true);
- RivelControlScript.EnableHeroMoving(true);
- this.schedule(function()
- {
- HeroControlScript.InitialPositionY = HeroControlScript.node.getPositionY();
- RivelControlScript.InitialPositionY = RivelControlScript.node.getPositionY();
- cc.find('UIControl').getComponent('GameUI').hideTimerTipOfNormalAcceleration(8);//普通加速带点击提示
- self.node.destroy();
- }, 0.01, 0);
- }
- });
|