【cocos creator】场景加载跳转代码,排行代码

场景加载跳转代码

// Learn cc.Class:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
        Number: cc.Label,
        barNumber: cc.ProgressBar,
        //ani: cc.Node,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
    },

    start() {
        cc.director.preloadScene("GameScene", this.onProgress.bind(this), function () {
            cc.director.loadScene('GameScene');
        });
        //this.SeverLink();
        //cc.director.loadScene('GameScene');

        //this.schedule(function () {
        //    cc.director.loadScene('GameScene');
        //}, 60, 10, 60);
    },

    onProgress: function (completedCount, totalCount, item) {
        this.barNumber.progress = (completedCount / totalCount);
        this.Number.string = Math.floor((completedCount / totalCount) * 100) + "%";
    },
    // update (dt) {},
});

排行代码

// Learn cc.Class:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

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();
            }
        },
    },

    // LIFE-CYCLE CALLBACKS:

    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();
        //itemlist.push(this.listItem.getComponent('RankItem'));
        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.node.active = false;
        this.closePanel();
        if (!window.wx) {
            return;
        }
    },

    closePanel() {
        this.node.destroy();
    },

    // update (dt) {},
});














  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

烧仙草奶茶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值