rankctrl.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // 排行榜控制器
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. normalbtn: {
  6. default: null,
  7. type: cc.Button,
  8. },
  9. infibtn: {
  10. default: null,
  11. type: cc.Button,
  12. },
  13. },
  14. // LIFE-CYCLE CALLBACKS:
  15. // onLoad () {},
  16. start () {
  17. this.initValues();
  18. this.initWx();
  19. },
  20. // 初始化
  21. // 初始化数据
  22. initValues:function() {
  23. // 加载全局变量
  24. this.global = require("global");
  25. },
  26. // 初始化微信数据
  27. initWx:function() {
  28. if (this.global) {
  29. console.log ("最高分 = " + this.global.bestscore);
  30. } else {
  31. console.log ("没有数据 ... ")
  32. }
  33. if (cc.sys.platform == cc.sys.WECHAT_GAME) {
  34. // 配置上传的数据
  35. var normalKv = {}
  36. normalKv.key = "normal_score"
  37. normalKv.value = this.global.bestscore.toString()
  38. var infiKv = {}
  39. infiKv.key = "infi_score";
  40. infiKv.value = this.global.besttime.toString()
  41. var kvList = [normalKv, infiKv]
  42. wx.setUserCloudStorage({
  43. KVDataList : kvList,
  44. success : function() {
  45. console.log ("设置成功")
  46. // 再通知开放数据域更新数据
  47. wx.postMessage({
  48. message: "updaterank"
  49. })
  50. },
  51. fail : function() {
  52. console.log ("设置失败")
  53. },
  54. complete : function() {
  55. console.log ("设置结束")
  56. }
  57. })
  58. }
  59. },
  60. // 事件
  61. // 返回按钮
  62. backClicked:function() {
  63. cc.director.loadScene("startscene")
  64. },
  65. // 切换到普通模式
  66. normalClicked:function() {
  67. // 自己隐藏,无限模式按钮显示
  68. // this.normalbtn.active = false
  69. // this.infibtn.active = true;
  70. console.log ("切换到普通模式 ... ")
  71. if (cc.sys.platform == cc.sys.WECHAT_GAME) {
  72. // 再通知开放数据域切换数据
  73. wx.postMessage({
  74. message: "show_normal_rank"
  75. })
  76. }
  77. },
  78. // 切换到无限模式
  79. infiClicked:function() {
  80. // 自己隐藏,普通模式按钮显示
  81. // this.normalbtn.active = true
  82. // this.infibtn.active = false;
  83. console.log ("切换到无限模式 ... ")
  84. if (cc.sys.platform == cc.sys.WECHAT_GAME) {
  85. // 再通知开放数据域切换数据
  86. wx.postMessage({
  87. message: "show_infi_rank"
  88. })
  89. }
  90. },
  91. });