cc.Class({ extends: cc.Component, properties: { PlayerDistance: 0, LastLoadedLvIndex: 0, TargetNum: 720 * 2, BgPrefabArray: [], AllBgPrefabArray: [], BAllSceneLoaded: false, PlayerInTheZone: 'None', PrePlayerInLvIndex: 0, CurrentPlayerInLvIndex: 0, FrontEnableLvIndex: 0, HasTiped: false, HasGetTipPositionX: false, TipLocationX: -1, SprintStartLinePositionX: 0, LongJumpStartLinePositionX: 0, HurdleStartLinePositionX: 0, JavelinStartLinePositionX: 0, RideBikeStartLinePositionX: 0, //起点 todo SprintStartLine: {//短跑起点 default: null, type: cc.Prefab }, LongJumpStartLine: {//跳远起点 default: null, type: cc.Prefab }, HurdleStartLine: {//跨栏起点 default: null, type: cc.Prefab }, JavelinStartLine: {//标枪起点 default: null, type: cc.Prefab }, BikeStartLine: {//骑车起点 default: null, type: cc.Prefab }, //终点 todo FinishLine_Sprint: {//短跑终点线 default: null, type: cc.Prefab }, LongJumpFinishLine: {//跳远终点 default: null, type: cc.Prefab }, FinishLine_Hurdle: {//跨栏终点 default: null, type: cc.Prefab }, JavelinFinishLine: {//标枪终点线 default: null, type: cc.Prefab }, // BikeFinishLine FinishLine_Bike: {//骑车终点 default: null, type: cc.Prefab }, // Hero: { // default: null, // type: cc.Node // }, Canvas: { default: null, type: cc.Node }, Blank: {//空白 default: null, type: cc.Prefab }, AccelerationBand30InTheMiddle: {//大加居中 default: null, type: cc.Prefab }, Cushion30AndRailingInTheMiddle: {//大缓跨栏居中 default: null, type: cc.Prefab }, JavelinModel: {//标枪模型 default: null, type: cc.Prefab }, LongAccelerationBand10ColumnTheLeftHalf1: {//长10加前半部分 default: null, type: cc.Prefab }, LongAccelerationBand10ColumnTheRightHalf2: {//长10加后半部分 default: null, type: cc.Prefab }, JavelinDistanceFirst: {//标枪计距带起点 default: null, type: cc.Prefab }, JavelinDistanceMiddle: {//标枪计距带中部10M-100M default: null, type: cc.Prefab }, JavelinDistanceLast: {//标枪计距带尾部110M default: null, type: cc.Prefab }, Cushion30AndBunker1M: {//沙坑1M default: null, type: cc.Prefab }, Bunker2to4M: {//沙坑2-4M default: null, type: cc.Prefab }, Bunker5to7M: {//沙坑5-7M default: null, type: cc.Prefab }, Bunker8to10M: {//沙坑8-10M default: null, type: cc.Prefab }, Bunker11M: {//沙坑11M default: null, type: cc.Prefab }, BikeModelToTheRight: {//自行车模型 default: null, type: cc.Prefab }, TwoAcceleration30s: {//两个大加1 default: null, type: cc.Prefab }, Acceleration30AndAcceleration20: {//两个大加2 default: null, type: cc.Prefab }, Acceleration20ToTheLeft: {//一个大加靠左 default: null, type: cc.Prefab }, LongAccelerationBand7Column: {//长7加1 default: null, type: cc.Prefab }, LongAccelerationBand10ColumnTheLeftHalf3: {//长10带边框1左半部分 default: null, type: cc.Prefab }, LongAccelerationBand10ColumnTheRightHalf4: {//长10带边框1右半部分 default: null, type: cc.Prefab }, LongAccelerationBand10ColumnTheLeftHalf5: {//长10带边框2左大半部分 default: null, type: cc.Prefab }, LongAccelerationBand10ColumnTheRightHalfAndLeftHalf6: {//长10带边框2右半部分及长10带边框3左小半部分 default: null, type: cc.Prefab }, LongAccelerationBand10ColumnTheRightHalf7: {//长10带边框3右半部分 default: null, type: cc.Prefab }, LongAccelerationBand10ColumnTheLeftHalf8: {//长10带边框4左半部分 default: null, type: cc.Prefab }, LongAccelerationBand10ColumnTheRightHalf9: {//长10带边框4右半部分 default: null, type: cc.Prefab }, AccelerationBand20InTheMiddle: {//中加居中 default: null, type: cc.Prefab }, AccelerationBand10InTheMiddle: {//小加居中 default: null, type: cc.Prefab }, JumpDownBike: {//下自行车 default: null, type: cc.Prefab }, JavelinBeginJump: {//标枪起跳 default: null, type: cc.Prefab }, LocationLine: { default: null, type: cc.Prefab }, YellowBG: { default: null, type: cc.Prefab }, wriggle_prefab: { default: null, type: cc.Prefab }, javeBg_prefab: { default: null, type: cc.Prefab }, JavalinDistance: 0, PrefabNumLabel: { default: null, type: cc.Prefab }, PlayerInLvIndexLabel: { default: null, type: cc.Prefab }, _GameUI: null, _getHero: null, _getRivel: null, _getJavetempHero: null, _getJavetempRivel: null, }, onLoad: function () { this._GameUI = cc.find('UIControl').getComponent('GameUI'); this._getHero = cc.find('Hero'); this._getRivel = cc.find('Rivel'); this._getJavetempHero = cc.find('javetemp_Hero'); this._getJavetempRivel = cc.find('javetemp_Rivel'); this.TipLocationX = -1; this.TargetNum = 720 * 3; this.JavalinDistance = 10; this.YellowBGArr = []; this.arrJavelin = []; // this.HasTiped = false; // this.testArr(false); // var data = { // gameLv: 0, // startPositionX: 0 // } // this.setStart(data); // this.PreLoad(); // var CameraNode = cc.find("CameraNode"); // var Hero = cc.find("Hero"); // CameraNode.parent = Hero; // setTimeout(function () { // this.onKeyDown(); // }.bind(this), 5000); }, start() { // this.scheduleOnce(function () { // 这里的 this 指向 component this.testArr(false); var data = { gameLv: 0, startPositionX: 0 } this.setStart(data); this.PreLoad(); // var CameraNode = cc.find("CameraNode"); // var Hero = cc.find("Hero"); // CameraNode.parent = Hero; // }, 0); }, //可以设置 加载几个项目 setStart: function (data) { // cc.log('就是看下setStart执行几次。。。。。。。。。。。。。'); if (data.gameLv == 1) { // cc.log('跨栏项目初始化!!!!!!!!!!!!!!'); } this.HasGetTipPositionX = false; this.TipLocationX = -1; this.tempArr = []; if (data == null) { } else { for (var i = 0; i < this.BgPrefabArray.length; i++) { if (this.BgPrefabArray[0]) { // this.BgPrefabArray[i].destroy(); this.BgPrefabArray.shift(); } } for (var i = 0; i < this.YellowBGArr.length; i++) { if (this.YellowBGArr[0]) { // this.YellowBGArr[i].destroy(); this.YellowBGArr.shift(); } } setTimeout(function () { this.delJaveLin(); }.bind(this), 5000); // for (var i = 0; i < this.AllBgPrefabArray.length; i++) { // this.AllBgPrefabArray[i].destroy(); // } // this.BgPrefabArray = []; // this.AllBgPrefabArray = []; // cc.log("要比赛的是什么",this.BgPrefabArr[0]); // if (data.gameLv == 0) { this.addPushArr(this.BgPrefabArr[0]); this.addPushArr(this.BgPrefabArr[1]); } else if (data.gameLv == 1) { this.addPushArr(this.BgPrefabArr[2]); this.addPushArr(this.BgPrefabArr[3]); } else if (data.gameLv == 2) { this.addPushArr(this.BgPrefabArr[4]); } } // cc.log("要比赛的是什么 1",this.tempArr); // this.AllBgPrefabArray = this.tempArr; // CustomLog("要比赛的是什么 1", this.AllBgPrefabArray); // cc.log("要比赛的是什么 2",this.AllBgPrefabArray); for (var i = 0; i < 4; i++) { this.LastLoadedLvIndex = i + 1; var tPrefab = cc.instantiate(this.tempArr[i]); tPrefab.parent = this.node; tPrefab.setAnchorPoint(0.5, 0.5); tPrefab.setLocalZOrder(-i); tPrefab.setPosition(data.startPositionX + i * (720), 0); // cc.log('prefab name is '+tPrefab.name+' and X is '+tPrefab.position.x); // cc.log('name is '+tPrefab.name+' ***************************************for loop'); this.BgPrefabArray.push(tPrefab); // this.AddIndexLabelToPrefab(i*(720));//此为预制体添加数字标签,正式项目可注释 this.setStartLine(tPrefab); } }, addJaveLin: function (javeLin) { this.arrJavelin.push(javeLin); }, delJaveLin: function () { if (this.arrJavelin&&this.arrJavelin.length != 0) { for (var i = 0; i < this.arrJavelin.length; i++) { this.arrJavelin[i].destroy(); } } }, addPushArr: function (arr) { for (var i = 0; i < arr.length; i++) { var node = arr[i]; this.tempArr.push(node); } }, testArr: function (b) { this.BgPrefabArr = []; //测试在这里修改 if (b) { this.BgPrefabArr[0] = [ //短跑 this.Blank,//空白 this.SprintStartLine,//短跑起点 // this.AccelerationBand30InTheMiddle,//短跑5个大加 // this.AccelerationBand30InTheMiddle, // this.AccelerationBand30InTheMiddle, // this.AccelerationBand30InTheMiddle, // this.AccelerationBand30InTheMiddle, this.AccelerationBand20InTheMiddle,//3个中加 this.AccelerationBand20InTheMiddle, this.AccelerationBand20InTheMiddle, this.FinishLine_Sprint,//终点线 ]; this.BgPrefabArr[1] = [ // 跳远 this.LongJumpStartLine,//跳远起点 this.AccelerationBand30InTheMiddle,//4个大加 this.AccelerationBand30InTheMiddle, // this.AccelerationBand30InTheMiddle, // this.AccelerationBand30InTheMiddle, // this.AccelerationBand20InTheMiddle,//3个中加 // this.AccelerationBand20InTheMiddle, // this.AccelerationBand20InTheMiddle, // this.LongAccelerationBand10ColumnTheLeftHalf1,//长10加前半部分 // this.LongAccelerationBand10ColumnTheRightHalf2,//长10加后半部分 // this.LongAccelerationBand10ColumnTheLeftHalf1,//长10加前半部分 // this.LongAccelerationBand10ColumnTheRightHalf2,//长10加后半部分 this.Cushion30AndBunker1M,//沙坑1M this.Bunker2to4M,//沙坑2-4M this.Bunker5to7M,//沙坑5-7M this.Bunker8to10M,//沙坑8-10M this.Bunker11M,//沙坑11M this.LongJumpFinishLine,//终点线 this.Blank,//空白 ]; this.BgPrefabArr[2] = [ // 跨栏 this.HurdleStartLine,//跨栏起点 this.Blank,//空白 this.AccelerationBand30InTheMiddle,//连续4个大加交替4个大缓跨栏 // this.Cushion30AndRailingInTheMiddle,//连续4个大加交替4个大缓跨栏 // this.Blank,//空白 // this.Blank,//空白 // this.AccelerationBand30InTheMiddle, // this.Cushion30AndRailingInTheMiddle, // this.Blank,//空白 // this.AccelerationBand30InTheMiddle, // this.Cushion30AndRailingInTheMiddle, // this.Blank,//空白 // this.AccelerationBand30InTheMiddle, // this.Cushion30AndRailingInTheMiddle, // this.Blank,//空白 // this.AccelerationBand30InTheMiddle, this.Cushion30AndRailingInTheMiddle, this.Blank,//空白 this.FinishLine_Hurdle,//终点线 this.Blank,//空白 ]; this.BgPrefabArr[3] = [ // 标枪 this.JavelinStartLine,//标枪起点 this.JavelinModel,//标枪模型 vvvvv this.AccelerationBand30InTheMiddle,//4个大加 // this.AccelerationBand30InTheMiddle, // this.AccelerationBand30InTheMiddle, // this.AccelerationBand30InTheMiddle, // this.AccelerationBand20InTheMiddle,//3个中加 // this.AccelerationBand20InTheMiddle, // this.AccelerationBand20InTheMiddle, // this.LongAccelerationBand10ColumnTheLeftHalf1,//长10加前半部分 // this.LongAccelerationBand10ColumnTheRightHalf2,//长10加后半部分 // this.LongAccelerationBand10ColumnTheLeftHalf1,//长10加前半部分 // this.LongAccelerationBand10ColumnTheRightHalf2,//长10加后半部分 this.javeBg_prefab,//起跳 this.JavelinDistanceFirst,//标枪距离计算起点 this.JavelinDistanceMiddle,//标枪距离计算中间部分共10个 this.JavelinDistanceMiddle, this.JavelinDistanceMiddle, this.JavelinDistanceMiddle, this.JavelinDistanceMiddle, this.JavelinDistanceMiddle, this.JavelinDistanceMiddle, this.JavelinDistanceMiddle, this.JavelinDistanceMiddle, this.JavelinDistanceMiddle, this.JavelinDistanceLast,//标枪距离计算末尾部分*/ this.JavelinFinishLine,//终点线 this.Blank,//空白 ]; this.BgPrefabArr[4] = [ //骑车 this.BikeStartLine,//骑车起点 this.BikeModelToTheRight,//自行车模型 this.TwoAcceleration30s,//3个大加2个中加 // this.Acceleration30AndAcceleration20,// // this.Acceleration20ToTheLeft,// this.LongAccelerationBand7Column,//1个长7 // this.LongAccelerationBand10ColumnTheLeftHalf3,//4个长10 // this.LongAccelerationBand10ColumnTheRightHalf4,// // this.LongAccelerationBand10ColumnTheLeftHalf5,// // this.LongAccelerationBand10ColumnTheRightHalfAndLeftHalf6,// // this.LongAccelerationBand10ColumnTheRightHalf7,// // this.LongAccelerationBand10ColumnTheLeftHalf8,// // this.LongAccelerationBand10ColumnTheRightHalf9,// this.Blank,// this.FinishLine_Bike,//终点线 this.Blank,// this.Blank,// this.Blank,// ] } else { this.BgPrefabArr[0] = [ //短跑 this.Blank,//空白 this.SprintStartLine,//短跑起点 this.AccelerationBand30InTheMiddle,//短跑5个大加 this.AccelerationBand30InTheMiddle, this.AccelerationBand30InTheMiddle, this.AccelerationBand30InTheMiddle, this.AccelerationBand30InTheMiddle, this.AccelerationBand20InTheMiddle,//3个中加 this.AccelerationBand20InTheMiddle, this.AccelerationBand20InTheMiddle, this.FinishLine_Sprint,//终点线 this.Blank,//空白 ]; this.BgPrefabArr[1] = [ // 跳远 this.LongJumpStartLine,//跳远起点 this.AccelerationBand30InTheMiddle,//4个大加 this.AccelerationBand30InTheMiddle, this.AccelerationBand30InTheMiddle, this.AccelerationBand30InTheMiddle, this.AccelerationBand20InTheMiddle,//3个中加 this.AccelerationBand20InTheMiddle, this.AccelerationBand20InTheMiddle, this.LongAccelerationBand10ColumnTheLeftHalf1,//长10加前半部分 this.LongAccelerationBand10ColumnTheRightHalf2,//长10加后半部分 this.LongAccelerationBand10ColumnTheLeftHalf1,//长10加前半部分 this.LongAccelerationBand10ColumnTheRightHalf2,//长10加后半部分 this.Cushion30AndBunker1M,//沙坑1M this.Bunker2to4M,//沙坑2-4M this.Bunker5to7M,//沙坑5-7M this.Bunker8to10M,//沙坑8-10M this.Bunker11M,//沙坑11M this.LongJumpFinishLine,//终点线 this.Blank,//空白 ]; this.BgPrefabArr[2] = [ // 跨栏 this.HurdleStartLine,//跨栏起点 this.Blank,//空白 this.AccelerationBand30InTheMiddle,//连续4个大加交替4个大缓跨栏 this.Cushion30AndRailingInTheMiddle,//连续4个大加交替4个大缓跨栏 this.Blank,//空白 this.Blank,//空白 this.AccelerationBand30InTheMiddle, this.Cushion30AndRailingInTheMiddle, this.Blank,//空白 this.AccelerationBand30InTheMiddle, this.Cushion30AndRailingInTheMiddle, this.Blank,//空白 this.AccelerationBand30InTheMiddle, this.Cushion30AndRailingInTheMiddle, this.Blank,//空白 this.AccelerationBand30InTheMiddle, this.Cushion30AndRailingInTheMiddle, this.Blank,//空白 this.FinishLine_Hurdle,//终点线 this.Blank,//空白 ]; this.BgPrefabArr[3] = [ // 标枪 this.JavelinStartLine,//标枪起点 this.JavelinModel,//标枪模型 vvvvv this.AccelerationBand30InTheMiddle,//4个大加 this.AccelerationBand30InTheMiddle, this.AccelerationBand30InTheMiddle, this.AccelerationBand30InTheMiddle, this.AccelerationBand20InTheMiddle,//3个中加 this.AccelerationBand20InTheMiddle, this.AccelerationBand20InTheMiddle, this.LongAccelerationBand10ColumnTheLeftHalf1,//长10加前半部分 this.LongAccelerationBand10ColumnTheRightHalf2,//长10加后半部分 this.LongAccelerationBand10ColumnTheLeftHalf1,//长10加前半部分 this.LongAccelerationBand10ColumnTheRightHalf2,//长10加后半部分 this.javeBg_prefab,//起跳 this.JavelinDistanceFirst,//标枪距离计算起点 this.JavelinDistanceMiddle,//标枪距离计算中间部分共10个 this.JavelinDistanceMiddle, this.JavelinDistanceMiddle, this.JavelinDistanceMiddle, this.JavelinDistanceMiddle, this.JavelinDistanceMiddle, this.JavelinDistanceMiddle, this.JavelinDistanceMiddle, this.JavelinDistanceMiddle, this.JavelinDistanceMiddle, this.JavelinDistanceLast,//标枪距离计算末尾部分*/ this.JavelinFinishLine,//终点线 this.Blank,//空白 ]; this.BgPrefabArr[4] = [ //骑车 this.BikeStartLine,//骑车起点 this.BikeModelToTheRight,//自行车模型 this.TwoAcceleration30s,//3个大加2个中加 this.Acceleration30AndAcceleration20,// this.Acceleration20ToTheLeft,// this.LongAccelerationBand7Column,//1个长7 this.LongAccelerationBand10ColumnTheLeftHalf3,//4个长10 this.LongAccelerationBand10ColumnTheRightHalf4,// this.LongAccelerationBand10ColumnTheLeftHalf5,// this.LongAccelerationBand10ColumnTheRightHalfAndLeftHalf6,// this.LongAccelerationBand10ColumnTheRightHalf7,// this.LongAccelerationBand10ColumnTheLeftHalf8,// this.LongAccelerationBand10ColumnTheRightHalf9,// this.Blank,// this.FinishLine_Bike,//终点线 this.Blank,// this.Blank,// this.Blank,// ] } }, PreLoad: function () { var aPrefab = cc.instantiate(this.YellowBG);//开始时加载一个长加速带的黄色区域,后面再次加载就不会卡 aPrefab.parent = this.node; aPrefab.setPosition(-1000, 1000); aPrefab.destroy(); var aPrefab = cc.instantiate(this._GameUI.UIPKScore);//开始时加载一下PK分数 aPrefab.parent = this.node; aPrefab.setPosition(-1000, 1000); aPrefab.destroy(); // CustomLog("我加载了几次"); // var bPrefab = cc.instantiate(this.PlayerInLvIndexLabel);//显示更前面的角色的LevelIndex。防止地图未加载。调试时用,正式版则注释掉 // bPrefab.parent = cc.find('UITop'); // bPrefab.setPosition(360,0); // this.PlayerInLvIndexLabel = bPrefab; }, onKeyDown: function (event) { if (event == null) { return; } switch (event.keyCode) { case cc.KEY.a: cc.log('Press a key'); var Hero = cc.find('Hero'); var Rivel = cc.find('Rivel'); var HeroHeroControl = Hero.getComponent("HeroControl"); var RivelHeroControl = Rivel.getComponent("HeroControl"); HeroHeroControl.SetSpeedToZeroAndIdle(); RivelHeroControl.SetSpeedToZeroAndIdle(); HeroHeroControl.javelinTag = false; RivelHeroControl.javelinTag = false; Hero.getChildByName('Player').stopAllActions(); Rivel.getChildByName('Player').stopAllActions(); Hero.getChildByName('Player').setPositionY(-132); Rivel.getChildByName('Player').setPositionY(-37); break; } }, SetDistance: function (aPlayerDistance) { if (this.PlayerDistance === aPlayerDistance) return; this.PlayerDistance = aPlayerDistance; // console.log('aPlayerDistance =',aPlayerDistance); }, SetLocationLine: function (PlayerCollisionLinePosition) { var aPrefab = cc.instantiate(this.LocationLine); aPrefab.parent = this.node; aPrefab.setPosition(PlayerCollisionLinePosition); }, CreateYellowBG: function (PlayerCollisionLinePosition) { var aPrefab = cc.instantiate(this.YellowBG); aPrefab.parent = this.node; this.YellowBGArr.push(aPrefab); // aPrefab.setAnchorPoint(0.5, 0.5); aPrefab.setPosition(PlayerCollisionLinePosition); return aPrefab; }, displayTimerMiddlePKScore: function (player) {//显示隐藏比分 if (player.name === 'Hero') { var MyScore = this._getHero.getComponent("PlayerState").TerminalPoint; var RivalScore = this._getRivel.getComponent("PlayerState").TerminalPoint; if (MyScore == 0 && RivalScore == 0) { return; } this._GameUI.displayTimerMiddlePKScore(MyScore, RivalScore, 0); } }, sortNumber: function (a, b) { return b - a }, update: function (dt) { // cc.log(this.BgPrefabArray); //var str = '["同意","不同意"]'; //var str2 = "test"; //var str3 = "xixixi"; // var data = { FunctionName: 'PushPlayerToEnterFinishLinePlayersArray' }; // var value = "{\"id\":\""+json[i].id+"\",\"text\":\""+json[i].text+"\"}," // var value = "{"+str2+":"+str3+"}"; //var value = "{"+str2+":"+str3+"}"; // var test3 = value.parseJSON(); // var test = JSON.stringify(value); // var test2 = JSON.parse(test.test); // cc.log(test3); // cc.log(this.StartLinesPositionXJson.LongJump); // var str = '0123456StartLine'; // var SubToStrIndex = str.length-9; // cc.log(str.substring(0,SubToStrIndex)); //cc.log('提示'+this.HasTiped+' 获取位置'+this.HasGetTipPositionX+' 提示位置'+this.TipLocationX+' hero位置'+cc.find('Hero').position.x); if (this.HasTiped == false) { if (this.TipLocationX != -1) { var HeroPositionX = this._getHero.position.x; if (HeroPositionX >= this.TipLocationX) { //cc.log('执行了###################'); //cc.log(this.TipLocationX+'****'+HeroPositionX); this._GameUI.hideTimerTipOfLongAcceleration(3);//长加速带长按提示 this.HasTiped = true; } } } // cc.log('提示'+this.HasTiped+' 获取位置'+this.HasGetTipPositionX+' 提示位置'+this.TipLocationX+' hero位置'+cc.find('Hero').position.x); // cc.log(this.TipLocationX + '=前面是提示位置后面是hero位置=' + cc.find('Hero').position.x); if (this.AllBgPrefabArray.length - 1 == this.LastLoadedLvIndex) return; var MaxPositionX = 0; // var MiniPosiitonX = 0; var HeroPositionX = this._getHero.position.x;//cc.find('Hero').position.x; var RivelPositionX = this._getRivel.position.x;// cc.find('Rivel').position.x; var JavalinHero = this._getJavetempHero;//cc.find('javetemp_Hero'); var JavalinHeroPositionX = 0; var JavalinRivel = this._getJavetempRivel;//cc.find('javetemp_Rivel'); var JavalinRivelPositionX = 0; var arr = []; if (JavalinHero != null || JavalinRivel != null) { if (JavalinHero != null && JavalinRivel != null) { if (JavalinHero.isTag) { JavalinHeroPositionX = JavalinHero.position.x; arr.push(JavalinHeroPositionX); } if (JavalinRivel.isTag) { JavalinRivelPositionX = JavalinRivel.position.x; arr.push(JavalinRivelPositionX); } arr.push(HeroPositionX); arr.push(RivelPositionX); } else if (JavalinHero != null) { if (JavalinHero.isTag) { JavalinHeroPositionX = JavalinHero.position.x; arr.push(JavalinHeroPositionX); } arr.push(HeroPositionX); arr.push(RivelPositionX); } else if (JavalinRivel != null) { if (JavalinRivel.isTag) { JavalinRivelPositionX = JavalinRivel.position.x; arr.push(JavalinRivelPositionX); } arr.push(HeroPositionX); arr.push(RivelPositionX); } //冒泡排序 HeroPositionX RivelPositionX JavalinHeroPositionX JavalinRivelPositionX arr.sort(this.sortNumber); MaxPositionX = arr[0]; // MiniPosiitonX = arr[arr.length - 1]; // CustomLog("现在的数组是","max",MaxPositionX,"min",MiniPosiitonX); // CustomLog("现在的数组是","arr",arr.length); } else { if (RivelPositionX - HeroPositionX > 0) { MaxPositionX = RivelPositionX; // MiniPosiitonX = HeroPositionX; } else { MaxPositionX = HeroPositionX; // MiniPosiitonX = RivelPositionX; } } var csPositionX = MaxPositionX + 360; this.CurrentPlayerInLvIndex = Math.floor(csPositionX / 720); // if(this.PlayerInLvIndexLabel!=null){ // this.PlayerInLvIndexLabel.getChildByName('label').getComponent(cc.Label).string = this.CurrentPlayerInLvIndex;//设置更前面的角色的levelIndex值,调试用。 // } // cc.log(this.LastLoadedLvIndex-this.CurrentPlayerInLvIndex) // cc.log('x=',this.CurrentPlayerInLvIndex-this.PrePlayerInLvIndex) // cc.log("last is "+this.LastLoadedLvIndex+' and currentP is '+this.CurrentPlayerInLvIndex+' and PrePlayer is '+this.PrePlayerInLvIndex); if (this.LastLoadedLvIndex - this.CurrentPlayerInLvIndex < 2 && this.CurrentPlayerInLvIndex != this.PrePlayerInLvIndex) { //汪汪开图 this.addMap(); // this.LastLoadedLvIndex++; // // CustomLog("这个对象",this.BgPrefabArray[this.BgPrefabArray.length-1]); // var LastLvPositionX = this.BgPrefabArray[this.BgPrefabArray.length - 1].position.x; // var NewLvPositionX = LastLvPositionX + 720; // CustomLog("新创建出来的 放到什么地方了",NewLvPositionX); // var tempArr= this.AllBgPrefabArray[this.LastLoadedLvIndex-1]; // CustomLog("不够了",tempArr); // var tPrefab = cc.instantiate(tempArr); // // cc.log(this.AllBgPrefabArray[this.LastLoadedLvIndex].name+"======name"+this.LastLoadedLvIndex); // tPrefab.parent = this.node; // tPrefab.setAnchorPoint(0.5, 0.5); // tPrefab.setLocalZOrder(-this.LastLoadedLvIndex); // tPrefab.setPosition(NewLvPositionX, 0); // // this.BgPrefabArray.shift().destroy(); // this.BgPrefabArray.push(tPrefab); // // cc.log(tPrefab.name+"======name"); // if (tPrefab.name == 'JavelinDistanceMiddle') { // var aLabel = tPrefab.getChildByName("JavelinDistanceNUM"); // var Labelcomp = aLabel.getComponent(cc.Label); // Labelcomp.string = this.JavalinDistance.toString(); // this.JavalinDistance += 10; // } // this.AddIndexLabelToPrefab(NewLvPositionX);//此为预制体添加数字标签,正式项目可注释 } this.PrePlayerInLvIndex = this.CurrentPlayerInLvIndex; // var MiniPlayerInIndex = Math.floor(MiniPosiitonX/720); // // // CustomLog("现在的数组是 索引",this.FrontEnableLvIndex); // if(MiniPlayerInIndex-this.FrontEnableLvIndex>2) // { // // cc.log('this.FrontEnableLvIndex='+this.FrontEnableLvIndex); // // this.BgPrefabArray.shift().destroy(); // // CustomLog("删除东西",this.BgPrefabArray[this.FrontEnableLvIndex]); // this.BgPrefabArray[this.FrontEnableLvIndex].destroy(); // // // cc.log(this.BgPrefabArray.length); // this.FrontEnableLvIndex++; // // // } }, addMap: function () { var lastIndex = this.AllBgPrefabArray.length - 1 - this.LastLoadedLvIndex; var tempIndex = 0; if (lastIndex > 3) { tempIndex = 3; } else { tempIndex = lastIndex; } for (var i = 0; i < tempIndex; i++) { this.LastLoadedLvIndex++; // cc.log("现在匹配是多少LastLoadedLvIndex",this.LastLoadedLvIndex); // CustomLog("这个对象",this.BgPrefabArray[this.BgPrefabArray.length-1]); var LastLvPositionX = this.BgPrefabArray[this.BgPrefabArray.length - 1].position.x; // cc.log("现在匹配是多少LastLvPositionX",LastLvPositionX); var NewLvPositionX = LastLvPositionX + 720; // cc.log("现在匹配是多少NewLvPositionX",NewLvPositionX); var tPrefab = cc.instantiate(this.AllBgPrefabArray[this.LastLoadedLvIndex]); // cc.log(this.AllBgPrefabArray[this.LastLoadedLvIndex].name+"======name"+this.LastLoadedLvIndex+'.......'+this.HasTiped); // cc.log("现在要出来什么",this.CurrentPlayerInLvIndex,i,tPrefab); tPrefab.parent = this.node; tPrefab.setAnchorPoint(0.5, 0.5); tPrefab.setLocalZOrder(-this.LastLoadedLvIndex); tPrefab.setPosition(NewLvPositionX, 0); if (this.HasTiped == false) { if (this.HasGetTipPositionX == false) { if (tPrefab.name == 'LongAccelerationBand10ColumnTheLeftHalf1') { var tPrefabX = tPrefab.position.x; this.TipLocationX = tPrefabX; //cc.log(this.TipLocationX+'==============='); this.HasGetTipPositionX = true; } } } var str = tPrefab.name; if (str.indexOf("StartLine") != -1) { var SubToStrIndex = str.length - 9; var StartLineName = str.substring(0, SubToStrIndex); var StartLinesPositionX = tPrefab.position.x + 720; this.SetStartLinesPositionX(StartLineName, StartLinesPositionX); } // cc.log("现在要出来什么",this.CurrentPlayerInLvIndex,i,tPrefab,NewLvPositionX); // this.BgPrefabArray.shift().destroy(); this.BgPrefabArray.push(tPrefab); // cc.log(tPrefab.name+"===========================================================name"); if (tPrefab.name == 'JavelinDistanceMiddle') { var aLabel = tPrefab.getChildByName("JavelinDistanceNUM"); var Labelcomp = aLabel.getComponent(cc.Label); Labelcomp.string = this.JavalinDistance.toString(); this.JavalinDistance += 10; } // this.AddIndexLabelToPrefab(NewLvPositionX);//此为预制体添加数字标签,正式项目可注释 this.setStartLine(tPrefab); } }, SetStartLinesPositionX: function (StartLineName, StartLinesPositionX) { // cc.log('name is '+StartLineName+' and x is '+StartLinesPositionX); if ('Sprint' == StartLineName) { this.SprintStartLinePositionX = StartLinesPositionX; } else if ('LongJump' == StartLineName) { this.LongJumpStartLinePositionX = StartLinesPositionX; } else if ('Hurdle' == StartLineName) { this.HurdleStartLinePositionX = StartLinesPositionX; } else if ('Javelin' == StartLineName) { this.JavelinStartLinePositionX = StartLinesPositionX; } else if ('RideBike' == StartLineName) { this.RideBikeStartLinePositionX = StartLinesPositionX; } }, AddIndexLabelToPrefab: function (NewLvPositionX) { /** **/ var PrefabNumLabelInstance = cc.instantiate(this.PrefabNumLabel); PrefabNumLabelInstance.parent = this.node; PrefabNumLabelInstance.setAnchorPoint(0, 0.5); PrefabNumLabelInstance.setLocalZOrder(1000); PrefabNumLabelInstance.setPosition(NewLvPositionX, 0); this.BgPrefabArray.push(PrefabNumLabelInstance); PrefabNumLabelInstance.getChildByName('MyNumLeft').getComponent(cc.Label).string = 'Left ' + this.LastLoadedLvIndex; PrefabNumLabelInstance.getChildByName('MyNumRight').getComponent(cc.Label).string = 'Right ' + this.LastLoadedLvIndex; /** **/ }, setP: function (tPrefab) { if (tPrefab.getChildByName("New Node") != null) { if (tPrefab.getChildByName("New Node").getComponent(cc.RigidBody) != null) { // CustomLog("gangti",tPrefab); tPrefab.getChildByName("New Node").getComponent(cc.RigidBody).syncPosition(); } } }, /** * 这个是设置 每一个 项目开头的 位置的方法 */ setStartLine: function (node) { switch (node.name) { case "SprintStartLine": case "LongJumpStartLine": case "HurdleStartLine": case "JavelinStartLine": case "BikeStartLine": this.tempStartNode = node; CustomLog("现在是啥啊", this.tempStartNode.name, node.x); break; } } });