window.bTurnsNumber = false; window.calorie = 0 window.turnsNum = 0 window.direction = 1 window.turnsNumber = function (turns){ if(window.bTurnsNumber) { console.log("turnsNumber:",turns); if(window.isAndroid) window.hardWare = turns else if(window.isiOS) window.hardWare = JSON.parse(turns) window.calorie = window.hardWare.calorie window.turnsNum = window.hardWare.turnsnumber window.direction = window.hardWare.direction } } window.submitScoreResponse = function(response){ console.log('submitScoreResponse:',response) } window.submitScoreOnError= function(response){ console.log('submitScoreOnError:',response) } var GameStates = require('GameStates'); cc.Class({ extends: cc.Component, properties: { bg:cc.Node, Champin:cc.Node, rankPanel:cc.Node, maxScoreLabel:cc.Label, monthRankContent:cc.Node, legendRankContent:cc.Node, crownFrame:[cc.SpriteFrame], numberFrame:[cc.SpriteFrame], headFrame:[cc.SpriteFrame], rankList:[cc.Prefab], myRank:cc.Node, //音效 sound:{ default:[], type: cc.AudioClip }, bgsound:{ default:[], type: cc.AudioClip }, }, // LIFE-CYCLE CALLBACKS: onLoad () { this.isAndroid = false; this.isiOS = false; window.isiOS = false window.isAndroid = false; console.log('平台信息=',navigator.userAgent); this.isAndroid = Boolean(navigator.userAgent.match(/android/ig)); window.isAndroid = this.isAndroid this.isIphone = Boolean(navigator.userAgent.match(/iphone|ipod/ig)); this.isIpad = Boolean(navigator.userAgent.match(/ipad/ig)); if(this.isIphone || this.isIpad) { this.isiOS = true; window.isiOS = true } if(this.isAndroid) { console.log('当前平台是:android') } else if(this.isiOS) { console.log('当前平台是:ios') } else { console.log('当前平台未检测到') } }, start () { if(cc.sys.localStorage.getItem('levelNumber')==null || cc.sys.localStorage.getItem('levelNumber')==''){ cc.sys.localStorage.setItem('levelNumber',1) cc.sys.localStorage.setItem('showRank',0) } GameStates.levelNum = parseInt(cc.sys.localStorage.getItem('levelNumber')) GameStates.gameScore = 0 this.node.getChildByName('Loading').active = true this.node.getChildByName('Loading').getChildByName('DOT0').runAction(cc.repeatForever(cc.sequence(cc.delayTime(0),cc.fadeIn(0),cc.delayTime(1.5),cc.fadeOut(0),cc.delayTime(0.5)))) this.node.getChildByName('Loading').getChildByName('DOT1').runAction(cc.repeatForever(cc.sequence(cc.delayTime(0.5),cc.fadeIn(0),cc.delayTime(1),cc.fadeOut(0),cc.delayTime(0.5)))) this.node.getChildByName('Loading').getChildByName('DOT2').runAction(cc.repeatForever(cc.sequence(cc.delayTime(1),cc.fadeIn(0),cc.delayTime(0.5),cc.fadeOut(0),cc.delayTime(0.5)))) var sceneName = 'GameScene' this.preloadScene(sceneName) if(parseInt(cc.sys.localStorage.getItem('showRank'))==1){ this.monthRank() this.rankPanel.active = true cc.sys.localStorage.setItem('showRank',0) } //关卡音乐 cc.audioEngine.play(this.bgsound[0],true) if(!((this.isAndroid && window.eventJsBridge.maxScore) || (this.isiOS && window.webkit.messageHandlers.maxScore))){ this.Champin.active = false } else{ if(this.isAndroid) { console.log('maxScore') window.eventJsBridge.maxScore() } else if(this.isiOS) { console.log('maxScore') window.webkit.messageHandlers.maxScore.postMessage(null); } var self = this window.maxScore = function(maxScore){ console.log('maxScore',maxScore) if(self.isAndroid){ var mymaxScore = maxScore self.maxScoreLabel.string = mymaxScore.maxScore } else if(self.isiOS){ var mymaxScore = JSON.parse(maxScore) self.maxScoreLabel.string = mymaxScore.maxScore } } } // var myRank = {} // myRank.portraits = 'https://dn-qn.move-it.club/syshead12006.jpg' // if(myRank.portraits.substring(myRank.portraits.length-4,myRank.portraits.length)=='.png' || myRank.portraits.substring(myRank.portraits.length-4,myRank.portraits.length)=='.jpg') // cc.loader.load({url: myRank.portraits}, function (err, frame) { // }) // else // cc.loader.load({url: myRank.portraits, type: 'png'}, function (err, frame) { // cc.log(new cc.SpriteFrame(frame)) // }) }, gameBegin(){ //接口 if(this.isAndroid) { console.log('isSendData') window.eventJsBridge.isSendData(true) } else if(this.isiOS) { console.log('isSendData') window.webkit.messageHandlers.isSendData.postMessage(true); } cc.audioEngine.play(this.sound[0],false) GameStates.gameTime = new Date() GameStates.levelNum = 1 GameStates.lifeNum = 3 GameStates.carlNum = window.calorie GameStates.turnsNum = window.turnsNum cc.director.loadScene('GameScene') }, gameRank(){ cc.audioEngine.play(this.sound[0],false) this.monthRank() this.rankPanel.active = true }, gameHome(){ cc.audioEngine.play(this.sound[0],false) // cc.director.loadScene('BeginScene') }, gameBack(){ if(this.isAndroid) { window.eventJsBridge.goBack() } else if(this.isiOS) { window.webkit.messageHandlers.goBack.postMessage(null) } }, onDestroy(){ cc.audioEngine.stopAllEffects() }, preloadScene (sceneName, onLoaded) { var info = cc.director._getSceneUuid(sceneName); if (info) { cc.director.emit(cc.Director.EVENT_BEFORE_SCENE_LOADING, sceneName); cc.loader.load({ uuid: info.uuid, type: 'uuid' }, (completedCount, totalCount, item) => { let _loadingNextStep = (completedCount / totalCount * 100); this.node.getChildByName('Loading').getChildByName('ProgressBar').getComponent(cc.ProgressBar).progress = (_loadingNextStep/100) // cc.log(this.node.getChildByName('ProgressBar').getComponent(cc.ProgressBar).progress,(_loadingNextStep/100)) if(Math.floor(_loadingNextStep)==100){ this.node.getChildByName('Loading').active = false } } , function (error, asset) { if (error) { } if (onLoaded) { onLoaded(error, asset); } }); } else { onLoaded(new Error()); } }, closeRank(){ cc.audioEngine.play(this.sound[0],false) this.rankPanel.active = false }, legendRank(){ cc.audioEngine.play(this.sound[0],false) this.rankPanel.getChildByName('legendRank').active = true this.rankPanel.getChildByName('monthRank').active = false this.rankPanel.getChildByName('monthBtn0').active = true this.rankPanel.getChildByName('monthBtn1').active = false this.rankPanel.getChildByName('legendBtn0').active = false this.rankPanel.getChildByName('legendBtn1').active = true this.legendRankContent.parent.parent.getComponent(cc.ScrollView).setContentPosition(cc.v2(0,350)) var str = '{"myRanking":{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12001.jpg","rank":1,"score":1000,"userId":14624607179958807},'+ '"rankingList":[{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12001.jpg","rank":1,"score":1000,"userId":14624607179958807},'+ '{"nickName":"乙","portraits":"https://dn-qn.move-it.club/syshead12009.jpg","rank":2,"score":800,"userId":11618408636521789},'+ '{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12006.jpg","rank":3,"score":700,"userId":22978961616130},'+ '{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12001.jpg","rank":4,"score":1000,"userId":14624607179958807},'+ '{"nickName":"乙","portraits":"https://dn-qn.move-it.club/syshead12009.jpg","rank":5,"score":800,"userId":11618408636521789},'+ '{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12006.jpg","rank":6,"score":700,"userId":22978961616130},'+ '{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12001.jpg","rank":7,"score":1000,"userId":14624607179958807},'+ '{"nickName":"乙","portraits":"https://dn-qn.move-it.club/syshead12009.jpg","rank":8,"score":800,"userId":11618408636521789},'+ '{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12006.jpg","rank":9,"score":700,"userId":22978961616130},'+ '{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12001.jpg","rank":10,"score":1000,"userId":14624607179958807},'+ '{"nickName":"乙","portraits":"https://dn-qn.move-it.club/syshead12009.jpg","rank":11,"score":800,"userId":11618408636521789},'+ '{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12006.jpg","rank":12,"score":700,"userId":22978961616130}]}' var str = '{"myRanking":{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12001.jpg","rank":1,"score":1000,"userId":14624607179958807},'+ '"rankingList":[{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12001.jpg","rank":1,"score":1000,"userId":14624607179958807}]}' var self = this this.monthRankContent.removeAllChildren() this.legendRankContent.removeAllChildren() if(this.isAndroid) { console.log('getRankingList2') window.eventJsBridge.getRankingList(2) } else if(this.isiOS) { console.log('getRankingList2') window.webkit.messageHandlers.getRankingList.postMessage(2); } window.rankingResponse= function(response){ console.log('rankin:',response) if(self.isAndroid) window.ranking = response else if(self.isiOS) window.ranking = JSON.parse(response) var myRank = window.ranking.myRanking var rankingList = window.ranking.rankingList // var myRank = JSON.parse(str).myRanking // var rankingList = JSON.parse(str).rankingList self.rankingList = rankingList self.myRank.getChildByName('name').getComponent(cc.Label).string = myRank.nickName self.myRank.getChildByName('score').getComponent(cc.Label).string = myRank.score+'分' self.myRank.getChildByName('rank').getComponent(cc.Label).string = myRank.rank if(!myRank.sex){ myRank.sex = 1 } if(myRank.portraits.substring(myRank.portraits.length-4,myRank.portraits.length)=='.png' || myRank.portraits.substring(myRank.portraits.length-4,myRank.portraits.length)=='.jpg') cc.loader.load({url: myRank.portraits}, function (err, frame) { if(err) self.myRank.getChildByName('mask').getChildByName('head').getComponent(cc.Sprite).spriteFrame = self.headFrame[myRank.sex-1] else self.myRank.getChildByName('mask').getChildByName('head').getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(frame) }) else cc.loader.load({url: myRank.portraits, type: 'png'}, function (err, frame) { if(err) self.myRank.getChildByName('mask').getChildByName('head').getComponent(cc.Sprite).spriteFrame = self.headFrame[myRank.sex-1] else self.myRank.getChildByName('mask').getChildByName('head').getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(frame) }) console.log(rankingList) //排序 for(var m=0;mnamenum1){ var rankList = rankingList[n] rankingList[n] = rankingList[n+1] rankingList[n+1] = rankList } } } //加载 var i = 0 self.legendRankContent.height = rankingList.length*120 self.rankListarr = [] var showRankingList = function(){ if(!rankingList[i].sex){ rankingList[i].sex = 1 } if(rankingList[i].portraits.substring(rankingList[i].portraits.length-4,rankingList[i].portraits.length)=='.png' || rankingList[i].portraits.substring(rankingList[i].portraits.length-4,rankingList[i].portraits.length)=='.jpg') cc.loader.load({url: rankingList[i].portraits}, function (err, frame) { if(err) rankingList[i].frame = self.headFrame[rankingList[i].sex-1] else rankingList[i].frame = new cc.SpriteFrame(frame) i++ self.topindex = 0 if(inamenum1){ var rankList = rankingList[n] rankingList[n] = rankingList[n+1] rankingList[n+1] = rankList } } } //加载 var i = 0 self.monthRankContent.height = rankingList.length*120 self.rankListarr = [] var showRankingList = function(){ if(!rankingList[i].sex){ rankingList[i].sex = 1 } if(rankingList[i].portraits.substring(rankingList[i].portraits.length-4,rankingList[i].portraits.length)=='.png' || rankingList[i].portraits.substring(rankingList[i].portraits.length-4,rankingList[i].portraits.length)=='.jpg') cc.loader.load({url: rankingList[i].portraits}, function (err, frame) { if(err) rankingList[i].frame = self.headFrame[rankingList[i].sex-1] else rankingList[i].frame = new cc.SpriteFrame(frame) i++ self.topindex = 0 if(i=this.rankingList.length) return var rankList = cc.instantiate(self.rankList[0]) rankList.index = j rankList.parent = content rankList.y = -j*120-70 if(j==0) self.topItem = rankList if(j==9) self.bottomItem = rankList var rankingList = this.rankingList cc.log(rankingList,rankList.index,self.topindex) rankList.getChildByName('mask').getChildByName('head').getComponent(cc.Sprite).spriteFrame = rankingList[(rankList.index+self.topindex)].frame rankList.getChildByName('name').getComponent(cc.Label).string = rankingList[(rankList.index+self.topindex)].nickName rankList.getChildByName('score').getComponent(cc.Label).string = rankingList[(rankList.index+self.topindex)].score rankList.getChildByName('rank').getComponent(cc.Label).string = rankingList[(rankList.index+self.topindex)].rank if((rankList.index+self.topindex)<3){ rankList.getChildByName('crown').active = true rankList.getChildByName('number').active = true rankList.getChildByName('crown').getComponent(cc.Sprite).spriteFrame = self.crownFrame[(rankList.index+self.topindex)] rankList.getChildByName('number').getComponent(cc.Sprite).spriteFrame = self.numberFrame[(rankList.index+self.topindex)] rankList.getChildByName('num').active = false rankList.getChildByName('rank').active = false } else{ rankList.getChildByName('crown').active = false rankList.getChildByName('number').active = false rankList.getChildByName('num').active = true } self.rankListarr.push(rankList) } }, update(){ if(this.rankPanel.getChildByName('legendRank').active) var height = this.legendRankContent.parent.parent.getComponent(cc.ScrollView).getContentPosition().y else var height = this.monthRankContent.parent.parent.getComponent(cc.ScrollView).getContentPosition().y if(height>(420+120*(this.topindex+1)) && this.topindex9?0:this.topItem.index+1 this.topItem = this.rankListarr[n] var rankList = this.bottomItem var rankingList = this.rankingList cc.log(this.topItem.y) rankList.getChildByName('mask').getChildByName('head').getComponent(cc.Sprite).spriteFrame = rankingList[this.topindex+9].frame rankList.getChildByName('name').getComponent(cc.Label).string = rankingList[(this.topindex+9)].nickName rankList.getChildByName('score').getComponent(cc.Label).string = rankingList[(this.topindex+9)].score rankList.getChildByName('rank').getComponent(cc.Label).string = rankingList[(this.topindex+9)].rank if((this.topindex+9)<3){ rankList.getChildByName('crown').active = true rankList.getChildByName('number').active = true rankList.getChildByName('crown').getComponent(cc.Sprite).spriteFrame = this.crownFrame[(this.topindex+9)] rankList.getChildByName('number').getComponent(cc.Sprite).spriteFrame = this.numberFrame[this.topindex+9] rankList.getChildByName('num').active = false rankList.getChildByName('rank').active = false } else{ rankList.getChildByName('crown').active = false rankList.getChildByName('number').active = false rankList.getChildByName('num').active = true rankList.getChildByName('rank').active = true } } if(height<(300+120*(this.topindex+1)) && this.topindex>0){ this.topindex-- this.bottomItem.y = this.topItem.y+120 this.topItem = this.bottomItem var n = (this.bottomItem.index-1)<0?9:this.bottomItem.index-1 this.bottomItem = this.rankListarr[n] var rankList = this.topItem var rankingList = this.rankingList cc.log(rankingList[this.topindex]) rankList.getChildByName('mask').getChildByName('head').getComponent(cc.Sprite).spriteFrame = rankingList[this.topindex].frame rankList.getChildByName('name').getComponent(cc.Label).string = rankingList[(this.topindex)].nickName rankList.getChildByName('score').getComponent(cc.Label).string = rankingList[(this.topindex)].score rankList.getChildByName('rank').getComponent(cc.Label).string = rankingList[(this.topindex)].rank if((this.topindex)<3){ rankList.getChildByName('crown').active = true rankList.getChildByName('number').active = true rankList.getChildByName('crown').getComponent(cc.Sprite).spriteFrame = this.crownFrame[(this.topindex)] rankList.getChildByName('number').getComponent(cc.Sprite).spriteFrame = this.numberFrame[this.topindex] rankList.getChildByName('num').active = false rankList.getChildByName('rank').active = false } else{ rankList.getChildByName('crown').active = false rankList.getChildByName('number').active = false rankList.getChildByName('num').active = true rankList.getChildByName('rank').active = true } }78 } });