123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- // 排行榜控制器
- cc.Class({
- extends: cc.Component,
- properties: {
- normalbtn: {
- default: null,
- type: cc.Button,
- },
- infibtn: {
- default: null,
- type: cc.Button,
- },
- },
- // LIFE-CYCLE CALLBACKS:
- // onLoad () {},
- start () {
- this.initValues();
- this.initWx();
- },
- // 初始化
- // 初始化数据
- initValues:function() {
- // 加载全局变量
- this.global = require("global");
- },
- // 初始化微信数据
- initWx:function() {
- if (this.global) {
- console.log ("最高分 = " + this.global.bestscore);
- } else {
- console.log ("没有数据 ... ")
- }
- if (cc.sys.platform == cc.sys.WECHAT_GAME) {
- // 配置上传的数据
- var normalKv = {}
- normalKv.key = "normal_score"
- normalKv.value = this.global.bestscore.toString()
- var infiKv = {}
- infiKv.key = "infi_score";
- infiKv.value = this.global.besttime.toString()
- var kvList = [normalKv, infiKv]
- wx.setUserCloudStorage({
- KVDataList : kvList,
- success : function() {
- console.log ("设置成功")
- // 再通知开放数据域更新数据
- wx.postMessage({
- message: "updaterank"
- })
- },
- fail : function() {
- console.log ("设置失败")
- },
- complete : function() {
- console.log ("设置结束")
- }
- })
- }
- },
-
- // 事件
- // 返回按钮
- backClicked:function() {
- cc.director.loadScene("startscene")
- },
- // 切换到普通模式
- normalClicked:function() {
- // 自己隐藏,无限模式按钮显示
- // this.normalbtn.active = false
- // this.infibtn.active = true;
- console.log ("切换到普通模式 ... ")
- if (cc.sys.platform == cc.sys.WECHAT_GAME) {
- // 再通知开放数据域切换数据
- wx.postMessage({
- message: "show_normal_rank"
- })
- }
- },
- // 切换到无限模式
- infiClicked:function() {
- // 自己隐藏,普通模式按钮显示
- // this.normalbtn.active = true
- // this.infibtn.active = false;
- console.log ("切换到无限模式 ... ")
- if (cc.sys.platform == cc.sys.WECHAT_GAME) {
- // 再通知开放数据域切换数据
- wx.postMessage({
- message: "show_infi_rank"
- })
- }
- },
- });
|