场景加载跳转代码
cc.Class({
extends: cc.Component,
properties: {
Number: cc.Label,
barNumber: cc.ProgressBar,
},
onLoad() {
},
start() {
cc.director.preloadScene("GameScene", this.onProgress.bind(this), function () {
cc.director.loadScene('GameScene');
});
},
onProgress: function (completedCount, totalCount, item) {
this.barNumber.progress = (completedCount / totalCount);
this.Number.string = Math.floor((completedCount / totalCount) * 100) + "%";
},
});
排行代码
const SDK = require("SDKUtil");
var curMod = cc.Class({
extends: cc.Component,
properties: {
listItem: cc.Node,
layoutNode: cc.Node,
myScoreLabel: cc.Label,
myRankLabel: cc.Label,
myName: cc.Label,
myPic: cc.Sprite,
wxRank: cc.Node,
Rank: cc.Node,
world: cc.Node,
shareBtn: cc.Node,
},
statics: {
_instance: null,
Instance() {
return curMod._instance;
},
_createPanel: function (para) {
var parentNode = cc.Canvas.instance.node;
var func = function (err, prefab) {
cc.log('cc.loader.loadRes: RankPanel');
if (err) {
cc.error(err.message || err);
return;
}
if (curMod._instance) {
return;
}
var newNode = cc.instantiate(prefab);
parentNode.addChild(newNode);
curMod._instance = newNode.getComponent("RankPanel");
curMod._instance.showPanel(para);
};
cc.loader.loadRes('Panel/RankPanel', func);
},
OpenPanel: function (para) {
if (curMod._instance == null) {
curMod._createPanel(para);
} else {
curMod._instance.showPanel(para);
}
},
ClosePanel: function () {
if (curMod._instance) {
curMod._instance.closePanel();
}
},
},
onLoad() {
curMod._instance = this;
if (!window.wx) {
this.wxRank.active = false;
}
},
btnClick: function () {
if (window.wx) {
var openDataContext = wx.getOpenDataContext();
openDataContext.postMessage({
text: "showRank",
});
}
},
postDataToWX: function () {
var kvDateList = new Array();
let collectCount = require('GameMgr').Instance().getCollectCount() + "";
let guanqia = require("PlayerMessage").Instance().GetUserData().max_Guanqia + "";
kvDateList.push({
key: "collectCount",
value: collectCount,
});
kvDateList.push({
key: "guanqia",
value: guanqia,
});
console.log("kvDateList:")
console.log(kvDateList)
if (window.wx) {
wx.setUserCloudStorage({
KVDataList: kvDateList,
success: function (res) {
console.log("wx.setUserCloudStorage success");
console.log(res);
},
fail: function (res) {
console.log("wx.setUserCloudStorage fail");
console.log(res);
}
});
}
},
onDestroy: function () {
curMod._instance = null;
},
showPanel() {
if (!window.wx) {
return;
}
var headurl = require("PlayerMessage").Instance().GetUserData().PLpicUrl;
var name = require("PlayerMessage").Instance().GetUserData().PLname;
if (!headurl) {
return;
}
var self = this;
cc.loader.load({ url: headurl }, function (err, texture) {
if (err) {
console.error(err);
return;
}
else {
self.myPic.spriteFrame = new cc.SpriteFrame(texture);
}
});
this.myName.string = name;
},
onShareBtn() {
SDK.ShareApp();
},
onEnable() {
if (window.wx) {
this.wxRank.active = true;
this.Rank.active = false;
this.postDataToWX();
this.btnClick();
this.world.active = false;
return;
}
this.shareBtn.active = false;
this.wxRank.active = false;
this.world.active = true;
this.Rank.active = true;
let itemlist = [];
this.layoutNode.removeAllChildren();
for (let i = 0; i < 20; i++) {
let newNode = cc.instantiate(this.listItem);
let item = newNode.getComponent('RankItem');
this.layoutNode.addChild(newNode);
itemlist.push(item);
}
cc.log("itemlist.length=" + itemlist.length);
let infos = this.createUserData();
let CollectCount = 10;
let mychapter = 25;
let myname = "666";
this.myName.string = myname;
this.myScoreLabel.string = CollectCount + "/60";
this.myRankLabel.string = "第" + mychapter + "关";
for (let i = 0; i < infos.length; i++) {
if (mychapter > infos[i].chapter) {
let my = {};
my.name = myname;
my.chapter = mychapter;
my.CollectCount = CollectCount;
infos.splice(i, 0, my);
break;
}
}
if (infos.length > 20) {
infos.pop();
}
for (let i = 0; i < infos.length; i++) {
itemlist[i].node.active = true;
itemlist[i].initItem(i + 1, infos[i].name, infos[i].chapter, infos[i].CollectCount);
}
},
createUserData() {
let chapter = [
60, 60, 60, 59, 58,
57, 56, 55, 55, 55,
55, 55, 55, 54, 53,
53, 53, 53, 53, 52
];
let CollectCount = [
10, 10, 10, 9, 9,
9, 9, 8, 8, 7,
7, 7, 7, 5, 4,
4, 4, 3, 3, 3
];
let names = [
'紫静冰情',
'漂亮口号',
'姬如炫蕊',
'呐阳光 、刺眼',
'私有物品',
'CC爱人',
'轻盈的诱惑',
'幕后丶胸手',
'女人的潜在能力',
'筱愛',
'明媚的憂傷',
'苞米地蒙靣俠',
'浮伤年华',
'孟婆卖萌不卖汤',
'柚子纪年',
'独恋猫的鱼',
'白茶与鹿',
'hoho666',
'忆挽青笙尽',
'骑鹅撵飞机',
'莣吥鋽の情',
'盗版的兄弟',
'狂剑メ血王',
'打个酱油卖个萌',
'时光吹老了少年',
'违心爱',
'飞天忍者猪',
];
let infos = [];
for (let i = 0; i < chapter.length; i++) {
let data = {};
data.name = names[i];
data.chapter = chapter[i];
data.CollectCount = CollectCount[i];
infos.push(data);
}
return infos;
},
onCloseBtnClicked() {
this.closePanel();
if (!window.wx) {
return;
}
},
closePanel() {
this.node.destroy();
},
});