Cocos creator 微信小游戏 加载远程资源启动页

直接上流程

1. 在项目的根路径下添加文件结构

Cocos creator 微信小游戏 加载远程资源启动页

Cocos creator 微信小游戏 加载远程资源启动页

2. loading-scene.js文件内容

Cocos creator 微信小游戏 加载远程资源启动页

var loadingBg = "https://com-eonsun-public.oss-cn-shanghai.aliyuncs.com/product/HappinessLength/LoadingPicture/bg.png";

 

var scene = new cc.Scene();

 

// 1. Add canvas component

var root = new cc.Node();

var canvas = root.addComponent(cc.Canvas);

root.parent = scene;

 

// 2. Add sprite component

var bgSprite = root.addComponent(cc.Sprite);

var createImage = function (sprite, url) {

if (cc.sys.platform == cc.sys.WECHAT_GAME) {

let image = wx.createImage();

image.onload = function () {

let texture = new cc.Texture2D();

texture.initWithElement(image);

texture.handleLoadedTexture();

sprite.spriteFrame = new cc.SpriteFrame(texture);

};

image.src = url;

}

};

createImage(bgSprite, loadingBg);

 

// 3. Add label component

var node = new cc.Node();

var label = node.addComponent(cc.Label);

label.fontSize = 25;

label.lineHeight = 30;

label.string = "正在加载资源中……";

node.parent = root;

 

module.exports = scene;

3. 发布微信小游戏

4. 打开main.xxx.js文件
5. 在onStart方法最前面添加
            var loadingScene = require('src/loading-scene.xxx');
            cc.director.runSceneImmediate(loadingScene);

Cocos creator 微信小游戏 加载远程资源启动页
6. 其中的"loading-scene.xxx"的xxx为src路径下实际loading-scene.xxx的名称,注意要加上

Cocos creator 微信小游戏 加载远程资源启动页

PS:cocos creator 1.9.3亲测可用,如有错误,欢迎拍砖。