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); } });