Commit 69ed4eda authored by wildfirecode's avatar wildfirecode

1

parent 8ccbd567
...@@ -115,16 +115,26 @@ export default class MainBase extends eui.UILayer { ...@@ -115,16 +115,26 @@ export default class MainBase extends eui.UILayer {
} }
} }
_firstBgLoaded = false;
loadFirstScreen() { loadFirstScreen() {
this.loadFirstBG((bitmap: egret.Bitmap) => {
const t = Date.now() - window['__startTime__'];
console.log(`首屏显示时间:${t}ms`);
layers.addFirstBackground(bitmap);
this._firstBgLoaded = true;
this.check();
});
}
loadFirstBG(callback) {
const onImageLoaded = (e: egret.Event) => { const onImageLoaded = (e: egret.Event) => {
const imageLoader: egret.ImageLoader = e.currentTarget; const imageLoader: egret.ImageLoader = e.currentTarget;
const bitmapData: egret.BitmapData = imageLoader.data; const bitmapData: egret.BitmapData = imageLoader.data;
const texture = new egret.Texture(); const texture = new egret.Texture();
texture._setBitmapData(bitmapData); texture._setBitmapData(bitmapData);
const bitmap = new egret.Bitmap(texture); const bitmap = new egret.Bitmap(texture);
layers.addFirstBackground(bitmap); callback(bitmap);
} }
const imageLoader = new egret.ImageLoader(); const imageLoader = new egret.ImageLoader();
imageLoader.once(egret.Event.COMPLETE, onImageLoaded, this); imageLoader.once(egret.Event.COMPLETE, onImageLoaded, this);
const url = getResPath() + "resource/assets/startScene/bg.jpg" const url = getResPath() + "resource/assets/startScene/bg.jpg"
...@@ -158,13 +168,25 @@ export default class MainBase extends eui.UILayer { ...@@ -158,13 +168,25 @@ export default class MainBase extends eui.UILayer {
}) })
} }
/** /**
* 创建场景界面 * 创建场景界面
* Create scene interface * Create scene interface
*/ */
_startSceneReady = false;
protected createGameScene() { protected createGameScene() {
layers.removeFirstBackground(); SceneCtrl.instance.change(ModuleTypes.START_SCENE, null, () => {
SceneCtrl.instance.change(ModuleTypes.START_SCENE); this._startSceneReady = true;
this.check();
});
}
check() {
if (this._startSceneReady && this._firstBgLoaded) {
layers.removeFirstBackground();
const t = Date.now() - window['__startTime__'];
console.log(`start scene显示时间:${t}ms`);
//开始场景图集和开始场景背景全部加载完成并显示
}
} }
} }
\ No newline at end of file
...@@ -14,21 +14,21 @@ export default class SceneCtrl { ...@@ -14,21 +14,21 @@ export default class SceneCtrl {
this._parent = parent; this._parent = parent;
} }
change(type: ModuleTypes, data?) { change(type: ModuleTypes, data?, onComplete?: Function) {
const cls = this._sceneClassMap[type]; const cls = this._sceneClassMap[type];
const scene: Scene = new cls(); const scene: Scene = new cls();
if (!window['development']) { if (!window['development']) {
Loading.instace.show(); Loading.instace.show();
RES.getResByUrl(`${scene.skinKey.toLowerCase()}_json`, (sheet: egret.SpriteSheet) => { RES.getResByUrl(`${scene.skinKey.toLowerCase()}_json`, (sheet: egret.SpriteSheet) => {
Loading.instace.hide(); Loading.instace.hide();
this.showAfterLoadAtlas(scene, data); this.showAfterLoadAtlas(scene, data, onComplete);
}, this, RES.ResourceItem.TYPE_SHEET); }, this, RES.ResourceItem.TYPE_SHEET);
} else { } else {
this.showAfterLoadAtlas(scene, data); this.showAfterLoadAtlas(scene, data, onComplete);
} }
} }
showAfterLoadAtlas(scene: Scene, data) { showAfterLoadAtlas(scene: Scene, data, onComplete: Function) {
if (this._currentScene) { if (this._currentScene) {
this._currentScene.destroy(); this._currentScene.destroy();
this._parent.removeChild(this._currentScene); this._parent.removeChild(this._currentScene);
...@@ -36,6 +36,7 @@ export default class SceneCtrl { ...@@ -36,6 +36,7 @@ export default class SceneCtrl {
scene.loadSkin(); scene.loadSkin();
scene.start(); scene.start();
this.addToStage(scene); this.addToStage(scene);
onComplete && onComplete();
} }
addMask() { addMask() {
......
...@@ -15,16 +15,21 @@ class Layers extends eui.UILayer { ...@@ -15,16 +15,21 @@ class Layers extends eui.UILayer {
this.addChild(this._topLayer); this.addChild(this._topLayer);
} }
_removeTag: number;
_bg: egret.Bitmap; _bg: egret.Bitmap;
addFirstBackground(bitmap: egret.Bitmap): any { addFirstBackground(bitmap: egret.Bitmap): any {
this._bg = bitmap; if (!this._removeTag) {
this._bottomLayer.addChild(bitmap); this._bg = bitmap;
this._bottomLayer.addChild(bitmap);
}
} }
removeFirstBackground(): any { removeFirstBackground(): any {
// if (this._bg) this._removeTag = 1;
// this._bottomLayer.removeChild(this._bg); if (this._bg) {
// this._bg = null; this._bottomLayer.removeChild(this._bg);
this._bg = null;
}
} }
get topLayer() { return this._topLayer } get topLayer() { return this._topLayer }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment