BeginCanvas.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. window.bTurnsNumber = false;
  2. window.calorie = 0
  3. window.turnsNum = 0
  4. window.direction = 1
  5. window.turnsNumber = function (turns){
  6. if(window.bTurnsNumber)
  7. {
  8. console.log("turnsNumber:",turns);
  9. if(window.isAndroid)
  10. window.hardWare = turns
  11. else if(window.isiOS)
  12. window.hardWare = JSON.parse(turns)
  13. window.calorie = window.hardWare.calorie
  14. window.turnsNum = window.hardWare.turnsnumber
  15. window.direction = window.hardWare.direction
  16. }
  17. }
  18. window.submitScoreResponse = function(response){
  19. console.log('submitScoreResponse:',response)
  20. }
  21. window.submitScoreOnError= function(response){
  22. console.log('submitScoreOnError:',response)
  23. }
  24. var GameStates = require('GameStates');
  25. cc.Class({
  26. extends: cc.Component,
  27. properties: {
  28. bg:cc.Node,
  29. Champin:cc.Node,
  30. rankPanel:cc.Node,
  31. maxScoreLabel:cc.Label,
  32. monthRankContent:cc.Node,
  33. legendRankContent:cc.Node,
  34. crownFrame:[cc.SpriteFrame],
  35. numberFrame:[cc.SpriteFrame],
  36. headFrame:[cc.SpriteFrame],
  37. rankList:[cc.Prefab],
  38. myRank:cc.Node,
  39. //音效
  40. sound:{
  41. default:[],
  42. type: cc.AudioClip
  43. },
  44. bgsound:{
  45. default:[],
  46. type: cc.AudioClip
  47. },
  48. },
  49. // LIFE-CYCLE CALLBACKS:
  50. onLoad () {
  51. this.isAndroid = false;
  52. this.isiOS = false;
  53. window.isiOS = false
  54. window.isAndroid = false;
  55. console.log('平台信息=',navigator.userAgent);
  56. this.isAndroid = Boolean(navigator.userAgent.match(/android/ig));
  57. window.isAndroid = this.isAndroid
  58. this.isIphone = Boolean(navigator.userAgent.match(/iphone|ipod/ig));
  59. this.isIpad = Boolean(navigator.userAgent.match(/ipad/ig));
  60. if(this.isIphone || this.isIpad)
  61. {
  62. this.isiOS = true;
  63. window.isiOS = true
  64. }
  65. if(this.isAndroid)
  66. {
  67. console.log('当前平台是:android')
  68. }
  69. else if(this.isiOS)
  70. {
  71. console.log('当前平台是:ios')
  72. }
  73. else
  74. {
  75. console.log('当前平台未检测到')
  76. }
  77. },
  78. start () {
  79. if(cc.sys.localStorage.getItem('levelNumber')==null || cc.sys.localStorage.getItem('levelNumber')==''){
  80. cc.sys.localStorage.setItem('levelNumber',1)
  81. cc.sys.localStorage.setItem('showRank',0)
  82. }
  83. GameStates.levelNum = parseInt(cc.sys.localStorage.getItem('levelNumber'))
  84. GameStates.gameScore = 0
  85. this.node.getChildByName('Loading').active = true
  86. 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))))
  87. 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))))
  88. 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))))
  89. var sceneName = 'GameScene'
  90. this.preloadScene(sceneName)
  91. if(parseInt(cc.sys.localStorage.getItem('showRank'))==1){
  92. this.monthRank()
  93. this.rankPanel.active = true
  94. cc.sys.localStorage.setItem('showRank',0)
  95. }
  96. //关卡音乐
  97. cc.audioEngine.play(this.bgsound[0],true)
  98. if(!((this.isAndroid && window.eventJsBridge.maxScore) || (this.isiOS && window.webkit.messageHandlers.maxScore))){
  99. this.Champin.active = false
  100. }
  101. else{
  102. if(this.isAndroid)
  103. {
  104. console.log('maxScore')
  105. window.eventJsBridge.maxScore()
  106. }
  107. else if(this.isiOS)
  108. {
  109. console.log('maxScore')
  110. window.webkit.messageHandlers.maxScore.postMessage(null);
  111. }
  112. var self = this
  113. window.maxScore = function(maxScore){
  114. console.log('maxScore',maxScore)
  115. if(self.isAndroid){
  116. var mymaxScore = maxScore
  117. self.maxScoreLabel.string = mymaxScore.maxScore
  118. }
  119. else if(self.isiOS){
  120. var mymaxScore = JSON.parse(maxScore)
  121. self.maxScoreLabel.string = mymaxScore.maxScore
  122. }
  123. }
  124. }
  125. // var myRank = {}
  126. // myRank.portraits = 'https://dn-qn.move-it.club/syshead12006.jpg'
  127. // if(myRank.portraits.substring(myRank.portraits.length-4,myRank.portraits.length)=='.png' || myRank.portraits.substring(myRank.portraits.length-4,myRank.portraits.length)=='.jpg')
  128. // cc.loader.load({url: myRank.portraits}, function (err, frame) {
  129. // })
  130. // else
  131. // cc.loader.load({url: myRank.portraits, type: 'png'}, function (err, frame) {
  132. // cc.log(new cc.SpriteFrame(frame))
  133. // })
  134. },
  135. gameBegin(){
  136. //接口
  137. if(this.isAndroid)
  138. {
  139. console.log('isSendData')
  140. window.eventJsBridge.isSendData(true)
  141. }
  142. else if(this.isiOS)
  143. {
  144. console.log('isSendData')
  145. window.webkit.messageHandlers.isSendData.postMessage(true);
  146. }
  147. cc.audioEngine.play(this.sound[0],false)
  148. GameStates.gameTime = new Date()
  149. GameStates.levelNum = 1
  150. GameStates.lifeNum = 3
  151. GameStates.carlNum = window.calorie
  152. GameStates.turnsNum = window.turnsNum
  153. cc.director.loadScene('GameScene')
  154. },
  155. gameRank(){
  156. cc.audioEngine.play(this.sound[0],false)
  157. this.monthRank()
  158. this.rankPanel.active = true
  159. },
  160. gameHome(){
  161. cc.audioEngine.play(this.sound[0],false)
  162. // cc.director.loadScene('BeginScene')
  163. },
  164. gameBack(){
  165. if(this.isAndroid)
  166. {
  167. window.eventJsBridge.goBack()
  168. }
  169. else if(this.isiOS)
  170. {
  171. window.webkit.messageHandlers.goBack.postMessage(null)
  172. }
  173. },
  174. onDestroy(){
  175. cc.audioEngine.stopAllEffects()
  176. },
  177. preloadScene (sceneName, onLoaded) {
  178. var info = cc.director._getSceneUuid(sceneName);
  179. if (info) {
  180. cc.director.emit(cc.Director.EVENT_BEFORE_SCENE_LOADING, sceneName);
  181. cc.loader.load({ uuid: info.uuid, type: 'uuid' },
  182. (completedCount, totalCount, item) => {
  183. let _loadingNextStep = (completedCount / totalCount * 100);
  184. this.node.getChildByName('Loading').getChildByName('ProgressBar').getComponent(cc.ProgressBar).progress = (_loadingNextStep/100)
  185. // cc.log(this.node.getChildByName('ProgressBar').getComponent(cc.ProgressBar).progress,(_loadingNextStep/100))
  186. if(Math.floor(_loadingNextStep)==100){
  187. this.node.getChildByName('Loading').active = false
  188. }
  189. }
  190. , function (error, asset) {
  191. if (error) {
  192. }
  193. if (onLoaded) {
  194. onLoaded(error, asset);
  195. }
  196. });
  197. }
  198. else {
  199. onLoaded(new Error());
  200. }
  201. },
  202. closeRank(){
  203. cc.audioEngine.play(this.sound[0],false)
  204. this.rankPanel.active = false
  205. },
  206. legendRank(){
  207. cc.audioEngine.play(this.sound[0],false)
  208. this.rankPanel.getChildByName('legendRank').active = true
  209. this.rankPanel.getChildByName('monthRank').active = false
  210. this.rankPanel.getChildByName('monthBtn0').active = true
  211. this.rankPanel.getChildByName('monthBtn1').active = false
  212. this.rankPanel.getChildByName('legendBtn0').active = false
  213. this.rankPanel.getChildByName('legendBtn1').active = true
  214. this.legendRankContent.parent.parent.getComponent(cc.ScrollView).setContentPosition(cc.v2(0,350))
  215. var str = '{"myRanking":{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12001.jpg","rank":1,"score":1000,"userId":14624607179958807},'+
  216. '"rankingList":[{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12001.jpg","rank":1,"score":1000,"userId":14624607179958807},'+
  217. '{"nickName":"乙","portraits":"https://dn-qn.move-it.club/syshead12009.jpg","rank":2,"score":800,"userId":11618408636521789},'+
  218. '{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12006.jpg","rank":3,"score":700,"userId":22978961616130},'+
  219. '{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12001.jpg","rank":4,"score":1000,"userId":14624607179958807},'+
  220. '{"nickName":"乙","portraits":"https://dn-qn.move-it.club/syshead12009.jpg","rank":5,"score":800,"userId":11618408636521789},'+
  221. '{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12006.jpg","rank":6,"score":700,"userId":22978961616130},'+
  222. '{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12001.jpg","rank":7,"score":1000,"userId":14624607179958807},'+
  223. '{"nickName":"乙","portraits":"https://dn-qn.move-it.club/syshead12009.jpg","rank":8,"score":800,"userId":11618408636521789},'+
  224. '{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12006.jpg","rank":9,"score":700,"userId":22978961616130},'+
  225. '{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12001.jpg","rank":10,"score":1000,"userId":14624607179958807},'+
  226. '{"nickName":"乙","portraits":"https://dn-qn.move-it.club/syshead12009.jpg","rank":11,"score":800,"userId":11618408636521789},'+
  227. '{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12006.jpg","rank":12,"score":700,"userId":22978961616130}]}'
  228. var str = '{"myRanking":{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12001.jpg","rank":1,"score":1000,"userId":14624607179958807},'+
  229. '"rankingList":[{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12001.jpg","rank":1,"score":1000,"userId":14624607179958807}]}'
  230. var self = this
  231. this.monthRankContent.removeAllChildren()
  232. this.legendRankContent.removeAllChildren()
  233. if(this.isAndroid)
  234. {
  235. console.log('getRankingList2')
  236. window.eventJsBridge.getRankingList(2)
  237. }
  238. else if(this.isiOS)
  239. {
  240. console.log('getRankingList2')
  241. window.webkit.messageHandlers.getRankingList.postMessage(2);
  242. }
  243. window.rankingResponse= function(response){
  244. console.log('rankin:',response)
  245. if(self.isAndroid)
  246. window.ranking = response
  247. else if(self.isiOS)
  248. window.ranking = JSON.parse(response)
  249. var myRank = window.ranking.myRanking
  250. var rankingList = window.ranking.rankingList
  251. // var myRank = JSON.parse(str).myRanking
  252. // var rankingList = JSON.parse(str).rankingList
  253. self.rankingList = rankingList
  254. self.myRank.getChildByName('name').getComponent(cc.Label).string = myRank.nickName
  255. self.myRank.getChildByName('score').getComponent(cc.Label).string = myRank.score+'分'
  256. self.myRank.getChildByName('rank').getComponent(cc.Label).string = myRank.rank
  257. if(!myRank.sex){
  258. myRank.sex = 1
  259. }
  260. if(myRank.portraits.substring(myRank.portraits.length-4,myRank.portraits.length)=='.png' || myRank.portraits.substring(myRank.portraits.length-4,myRank.portraits.length)=='.jpg')
  261. cc.loader.load({url: myRank.portraits}, function (err, frame) {
  262. if(err)
  263. self.myRank.getChildByName('mask').getChildByName('head').getComponent(cc.Sprite).spriteFrame = self.headFrame[myRank.sex-1]
  264. else
  265. self.myRank.getChildByName('mask').getChildByName('head').getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(frame)
  266. })
  267. else
  268. cc.loader.load({url: myRank.portraits, type: 'png'}, function (err, frame) {
  269. if(err)
  270. self.myRank.getChildByName('mask').getChildByName('head').getComponent(cc.Sprite).spriteFrame = self.headFrame[myRank.sex-1]
  271. else
  272. self.myRank.getChildByName('mask').getChildByName('head').getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(frame)
  273. })
  274. console.log(rankingList)
  275. //排序
  276. for(var m=0;m<rankingList.length-1;m++){
  277. for(var n=0;n<rankingList.length-1;n++){
  278. var namenum = parseInt(rankingList[n].rank)
  279. var namenum1 = parseInt(rankingList[n+1].rank)
  280. if(namenum>namenum1){
  281. var rankList = rankingList[n]
  282. rankingList[n] = rankingList[n+1]
  283. rankingList[n+1] = rankList
  284. }
  285. }
  286. }
  287. //加载
  288. var i = 0
  289. self.legendRankContent.height = rankingList.length*120
  290. self.rankListarr = []
  291. var showRankingList = function(){
  292. if(!rankingList[i].sex){
  293. rankingList[i].sex = 1
  294. }
  295. 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')
  296. cc.loader.load({url: rankingList[i].portraits}, function (err, frame) {
  297. if(err)
  298. rankingList[i].frame = self.headFrame[rankingList[i].sex-1]
  299. else
  300. rankingList[i].frame = new cc.SpriteFrame(frame)
  301. i++
  302. self.topindex = 0
  303. if(i<rankingList.length)
  304. showRankingList()
  305. else
  306. self.showrankListarr(self.legendRankContent)
  307. })
  308. else
  309. cc.loader.load({url: rankingList[i].portraits, type: 'png'}, function (err, frame) {
  310. if(err)
  311. rankingList[i].frame = self.headFrame[rankingList[i].sex-1]
  312. else
  313. rankingList[i].frame = new cc.SpriteFrame(frame)
  314. i++
  315. self.topindex = 0
  316. if(i<rankingList.length)
  317. showRankingList()
  318. else
  319. self.showrankListarr(self.legendRankContent)
  320. })
  321. }
  322. showRankingList()
  323. }
  324. // window.rankingResponse()
  325. },
  326. monthRank(){
  327. cc.audioEngine.play(this.sound[0],false)
  328. this.rankPanel.getChildByName('legendRank').active = false
  329. this.rankPanel.getChildByName('monthRank').active = true
  330. this.rankPanel.getChildByName('monthBtn0').active = false
  331. this.rankPanel.getChildByName('monthBtn1').active = true
  332. this.rankPanel.getChildByName('legendBtn0').active = true
  333. this.rankPanel.getChildByName('legendBtn1').active = false
  334. this.monthRankContent.parent.parent.getComponent(cc.ScrollView).setContentPosition(cc.v2(0,350))
  335. var str = '{"myRanking":{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12001.jpg","rank":1,"score":1000,"userId":14624607179958807},'+
  336. '"rankingList":[{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12001.jpg","rank":1,"score":1000,"userId":14624607179958807},'+
  337. '{"nickName":"乙","portraits":"https://dn-qn.move-it.club/syshead12009.jpg","rank":2,"score":800,"userId":11618408636521789},'+
  338. '{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12006.jpg","rank":3,"score":700,"userId":22978961616130},'+
  339. '{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12001.jpg","rank":4,"score":1000,"userId":14624607179958807},'+
  340. '{"nickName":"乙","portraits":"https://dn-qn.move-it.club/syshead12009.jpg","rank":5,"score":800,"userId":11618408636521789},'+
  341. '{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12006.jpg","rank":6,"score":700,"userId":22978961616130},'+
  342. '{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12001.jpg","rank":7,"score":1000,"userId":14624607179958807},'+
  343. '{"nickName":"乙","portraits":"https://dn-qn.move-it.club/syshead12009.jpg","rank":8,"score":800,"userId":11618408636521789},'+
  344. '{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12006.jpg","rank":9,"score":700,"userId":22978961616130},'+
  345. '{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12001.jpg","rank":10,"score":1000,"userId":14624607179958807},'+
  346. '{"nickName":"乙","portraits":"https://dn-qn.move-it.club/syshead12009.jpg","rank":11,"score":800,"userId":11618408636521789},'+
  347. '{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12006.jpg","rank":12,"score":700,"userId":22978961616130}]}'
  348. // var str = '{"myRanking":{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12001.jpg","rank":1,"score":1000,"userId":14624607179958807},'+
  349. // '"rankingList":[{"nickName":"甲","portraits":"https://dn-qn.move-it.club/syshead12001.jpg","rank":1,"score":1000,"userId":14624607179958807}]}'
  350. var self = this
  351. this.monthRankContent.removeAllChildren()
  352. this.legendRankContent.removeAllChildren()
  353. if(this.isAndroid)
  354. {
  355. console.log('getRankingList1')
  356. window.eventJsBridge.getRankingList(1)
  357. }
  358. else if(this.isiOS)
  359. {
  360. console.log('getRankingList1')
  361. window.webkit.messageHandlers.getRankingList.postMessage(1);
  362. }
  363. window.rankingResponse= function(response){
  364. console.log('rankin:',response)
  365. if(self.isAndroid)
  366. window.ranking = response
  367. else if(self.isiOS)
  368. window.ranking = JSON.parse(response)
  369. var myRank = window.ranking.myRanking
  370. var rankingList = window.ranking.rankingList
  371. // var myRank = JSON.parse(str).myRanking
  372. // var rankingList = JSON.parse(str).rankingList
  373. self.rankingList = rankingList
  374. self.myRank.getChildByName('name').getComponent(cc.Label).string = myRank.nickName
  375. self.myRank.getChildByName('score').getComponent(cc.Label).string = myRank.score+'分'
  376. self.myRank.getChildByName('rank').getComponent(cc.Label).string = myRank.rank
  377. if(!myRank.sex){
  378. myRank.sex = 1
  379. }
  380. if(myRank.portraits.substring(myRank.portraits.length-4,myRank.portraits.length)=='.png' || myRank.portraits.substring(myRank.portraits.length-4,myRank.portraits.length)=='.jpg')
  381. cc.loader.load({url: myRank.portraits}, function (err, frame) {
  382. if(err)
  383. self.myRank.getChildByName('mask').getChildByName('head').getComponent(cc.Sprite).spriteFrame = self.headFrame[myRank.sex-1]
  384. else
  385. self.myRank.getChildByName('mask').getChildByName('head').getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(frame)
  386. })
  387. else
  388. cc.loader.load({url: myRank.portraits, type: 'png'}, function (err, frame) {
  389. if(err)
  390. self.myRank.getChildByName('mask').getChildByName('head').getComponent(cc.Sprite).spriteFrame = self.headFrame[myRank.sex-1]
  391. else
  392. self.myRank.getChildByName('mask').getChildByName('head').getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(frame)
  393. })
  394. console.log(rankingList)
  395. //排序
  396. for(var m=0;m<rankingList.length-1;m++){
  397. for(var n=0;n<rankingList.length-1;n++){
  398. var namenum = parseInt(rankingList[n].rank)
  399. var namenum1 = parseInt(rankingList[n+1].rank)
  400. if(namenum>namenum1){
  401. var rankList = rankingList[n]
  402. rankingList[n] = rankingList[n+1]
  403. rankingList[n+1] = rankList
  404. }
  405. }
  406. }
  407. //加载
  408. var i = 0
  409. self.monthRankContent.height = rankingList.length*120
  410. self.rankListarr = []
  411. var showRankingList = function(){
  412. if(!rankingList[i].sex){
  413. rankingList[i].sex = 1
  414. }
  415. 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')
  416. cc.loader.load({url: rankingList[i].portraits}, function (err, frame) {
  417. if(err)
  418. rankingList[i].frame = self.headFrame[rankingList[i].sex-1]
  419. else
  420. rankingList[i].frame = new cc.SpriteFrame(frame)
  421. i++
  422. self.topindex = 0
  423. if(i<rankingList.length)
  424. showRankingList()
  425. else
  426. self.showrankListarr(self.monthRankContent)
  427. })
  428. else
  429. cc.loader.load({url: rankingList[i].portraits, type: 'png'}, function (err, frame) {
  430. if(err)
  431. rankingList[i].frame = self.headFrame[rankingList[i].sex-1]
  432. else
  433. rankingList[i].frame = new cc.SpriteFrame(frame)
  434. i++
  435. self.topindex = 0
  436. if(i<rankingList.length)
  437. showRankingList()
  438. else
  439. self.showrankListarr(self.monthRankContent)
  440. })
  441. }
  442. showRankingList()
  443. }
  444. // window.rankingResponse()
  445. },
  446. showrankListarr(content){
  447. var self = this
  448. for(var j=0;j<10;j++){
  449. if(j>=this.rankingList.length)
  450. return
  451. var rankList = cc.instantiate(self.rankList[0])
  452. rankList.index = j
  453. rankList.parent = content
  454. rankList.y = -j*120-70
  455. if(j==0)
  456. self.topItem = rankList
  457. if(j==9)
  458. self.bottomItem = rankList
  459. var rankingList = this.rankingList
  460. cc.log(rankingList,rankList.index,self.topindex)
  461. rankList.getChildByName('mask').getChildByName('head').getComponent(cc.Sprite).spriteFrame = rankingList[(rankList.index+self.topindex)].frame
  462. rankList.getChildByName('name').getComponent(cc.Label).string = rankingList[(rankList.index+self.topindex)].nickName
  463. rankList.getChildByName('score').getComponent(cc.Label).string = rankingList[(rankList.index+self.topindex)].score
  464. rankList.getChildByName('rank').getComponent(cc.Label).string = rankingList[(rankList.index+self.topindex)].rank
  465. if((rankList.index+self.topindex)<3){
  466. rankList.getChildByName('crown').active = true
  467. rankList.getChildByName('number').active = true
  468. rankList.getChildByName('crown').getComponent(cc.Sprite).spriteFrame = self.crownFrame[(rankList.index+self.topindex)]
  469. rankList.getChildByName('number').getComponent(cc.Sprite).spriteFrame = self.numberFrame[(rankList.index+self.topindex)]
  470. rankList.getChildByName('num').active = false
  471. rankList.getChildByName('rank').active = false
  472. }
  473. else{
  474. rankList.getChildByName('crown').active = false
  475. rankList.getChildByName('number').active = false
  476. rankList.getChildByName('num').active = true
  477. }
  478. self.rankListarr.push(rankList)
  479. }
  480. },
  481. update(){
  482. if(this.rankPanel.getChildByName('legendRank').active)
  483. var height = this.legendRankContent.parent.parent.getComponent(cc.ScrollView).getContentPosition().y
  484. else
  485. var height = this.monthRankContent.parent.parent.getComponent(cc.ScrollView).getContentPosition().y
  486. if(height>(420+120*(this.topindex+1)) && this.topindex<this.rankingList.length-10){
  487. this.topindex++
  488. this.topItem.y = this.bottomItem.y-120
  489. this.bottomItem = this.topItem
  490. var n = (this.topItem.index+1)>9?0:this.topItem.index+1
  491. this.topItem = this.rankListarr[n]
  492. var rankList = this.bottomItem
  493. var rankingList = this.rankingList
  494. cc.log(this.topItem.y)
  495. rankList.getChildByName('mask').getChildByName('head').getComponent(cc.Sprite).spriteFrame = rankingList[this.topindex+9].frame
  496. rankList.getChildByName('name').getComponent(cc.Label).string = rankingList[(this.topindex+9)].nickName
  497. rankList.getChildByName('score').getComponent(cc.Label).string = rankingList[(this.topindex+9)].score
  498. rankList.getChildByName('rank').getComponent(cc.Label).string = rankingList[(this.topindex+9)].rank
  499. if((this.topindex+9)<3){
  500. rankList.getChildByName('crown').active = true
  501. rankList.getChildByName('number').active = true
  502. rankList.getChildByName('crown').getComponent(cc.Sprite).spriteFrame = this.crownFrame[(this.topindex+9)]
  503. rankList.getChildByName('number').getComponent(cc.Sprite).spriteFrame = this.numberFrame[this.topindex+9]
  504. rankList.getChildByName('num').active = false
  505. rankList.getChildByName('rank').active = false
  506. }
  507. else{
  508. rankList.getChildByName('crown').active = false
  509. rankList.getChildByName('number').active = false
  510. rankList.getChildByName('num').active = true
  511. rankList.getChildByName('rank').active = true
  512. }
  513. }
  514. if(height<(300+120*(this.topindex+1)) && this.topindex>0){
  515. this.topindex--
  516. this.bottomItem.y = this.topItem.y+120
  517. this.topItem = this.bottomItem
  518. var n = (this.bottomItem.index-1)<0?9:this.bottomItem.index-1
  519. this.bottomItem = this.rankListarr[n]
  520. var rankList = this.topItem
  521. var rankingList = this.rankingList
  522. cc.log(rankingList[this.topindex])
  523. rankList.getChildByName('mask').getChildByName('head').getComponent(cc.Sprite).spriteFrame = rankingList[this.topindex].frame
  524. rankList.getChildByName('name').getComponent(cc.Label).string = rankingList[(this.topindex)].nickName
  525. rankList.getChildByName('score').getComponent(cc.Label).string = rankingList[(this.topindex)].score
  526. rankList.getChildByName('rank').getComponent(cc.Label).string = rankingList[(this.topindex)].rank
  527. if((this.topindex)<3){
  528. rankList.getChildByName('crown').active = true
  529. rankList.getChildByName('number').active = true
  530. rankList.getChildByName('crown').getComponent(cc.Sprite).spriteFrame = this.crownFrame[(this.topindex)]
  531. rankList.getChildByName('number').getComponent(cc.Sprite).spriteFrame = this.numberFrame[this.topindex]
  532. rankList.getChildByName('num').active = false
  533. rankList.getChildByName('rank').active = false
  534. }
  535. else{
  536. rankList.getChildByName('crown').active = false
  537. rankList.getChildByName('number').active = false
  538. rankList.getChildByName('num').active = true
  539. rankList.getChildByName('rank').active = true
  540. }
  541. }78
  542. }
  543. });