launcher-scene.js
2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// var loadingBg = "launcher/default_sprite_splash.png"
var logo = "launcher/logo.png"
cc.debug.setDisplayStats(false);
var scene = new cc.Scene();
var root = new cc.Node();
root.parent = scene;
var widget = root.addComponent(cc.Widget);
widget.top = widget.bottom = widget.left = widget.right = 0;
widget.isAlignTop = widget.isAlignBottom = widget.isAlignLeft = widget.isAlignRight = true;
var canvas = root.addComponent(cc.Canvas);
canvas.designResolution = cc.size(720, 1280);
canvas.fitWidth = true;
canvas.fitHeight = false;
var createImage = function (sprite, url) {
var image = wx.createImage();
image.onload = function () {
var texture = new cc.Texture2D();
texture.initWithElement(image);
texture.handleLoadedTexture();
sprite.spriteFrame = new cc.SpriteFrame(texture);
};
image.src = url;
}
// var bgNode = new cc.Node();
// bgNode.parent = root;
// widget = bgNode.addComponent(cc.Widget);
// widget.top = widget.bottom = widget.left = widget.right = 0;
// widget.isAlignTop = widget.isAlignBottom = widget.isAlignLeft = widget.isAlignRight = true;
// var bgSprite = bgNode.addComponent(cc.Sprite);
// bgSprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
// createImage(bgSprite, loadingBg);
var cameraNode = new cc.Node();
cameraNode.parent = root;
var camera = cameraNode.addComponent(cc.Camera);
camera.clearFlags = cc.Camera.ClearFlags.COLOR;
camera.backgroundColor = new cc.Color(255, 255, 255);
var logoNode = new cc.Node();
logoNode.parent = root;
var logoSprite = logoNode.addComponent(cc.Sprite);
createImage(logoSprite, logo);
scene.loadinglaunchScene = function (launchScene) {
cc.director.preloadScene(launchScene, (completedCount, totalCount, item) => {
}, (error) => {
if (error) {
console.log('preloadScene error', launchScene, error)
}
let fadeout = cc.fadeOut(0.5);
root.runAction(cc.sequence(fadeout, cc.callFunc(() => {
cc.director.loadScene(launchScene, null, function () {
cc.loader.onProgress = null;
}
);
})));
})
}
module.exports = scene;