launcher-scene.js 2.01 KB
// 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;