Commit de78d61c authored by wildfirecode's avatar wildfirecode

1

parent e30ced12
......@@ -84,12 +84,6 @@ export default class MainBase extends eui.UILayer {
DataManager.ins.gameCfgData = window['CFG'];
DataManager.ins.gameCfgData.gameInfo.gameId = window["gameId"];
setTimeout(() => {
console.log('stageHeight', this.stage.stageHeight);
console.log('height', this.stage.height);
}, 2000);
layers.init(this);
Loading.init(layers.topLayer);
PanelCtrl.instance.init(layers.popupLayer);
......@@ -99,6 +93,8 @@ export default class MainBase extends eui.UILayer {
this.registerModules();
this.loadFirstScreen();
this.loadAtlas();
this.getData();
RES.setMaxLoadingThread(10);
this.runGame().catch(e => {
......@@ -106,6 +102,35 @@ export default class MainBase extends eui.UILayer {
})
}
loadAtlas() {
if (!window['development']) {
const urlJSON = getResPath() + "resource/TextureMerger/loading.json";
const request = new egret.HttpRequest();
request.open(urlJSON, egret.HttpMethod.GET);
request.send();
const url = getResPath() + "resource/TextureMerger/loading.png";
const imageLoader = new egret.ImageLoader();
imageLoader.load(url);
}
}
loadFirstScreen() {
const onImageLoaded = (e: egret.Event) => {
const imageLoader: egret.ImageLoader = e.currentTarget;
const bitmapData: egret.BitmapData = imageLoader.data;
const texture = new egret.Texture();
texture._setBitmapData(bitmapData);
const bitmap = new egret.Bitmap(texture);
layers.addFirstBackground(bitmap);
}
const imageLoader = new egret.ImageLoader();
imageLoader.once(egret.Event.COMPLETE, onImageLoaded, this);
const url = getResPath() + "resource/assets/startScene/bg.jpg"
imageLoader.load(url);
}
private async runGame() {
await this.loadResource()
this.createGameScene();
......@@ -139,6 +164,7 @@ export default class MainBase extends eui.UILayer {
* Create scene interface
*/
protected createGameScene() {
layers.removeFirstBackground();
SceneCtrl.instance.change(ModuleTypes.START_SCENE);
}
}
\ No newline at end of file
const loadAtlas = (name: string) => {
return new Promise((resolve, reject) => {
RES.getResByUrl(`resource/TextureMerger/${name}.json`, (sheet: egret.SpriteSheet) => {
resolve(this);
}, this, RES.ResourceItem.TYPE_SHEET);
});
}
// const loadAtlas = (name: string) => {
// return new Promise((resolve, reject) => {
// RES.getResByUrl(`resource/TextureMerger/${name}.json`, (sheet: egret.SpriteSheet) => {
// resolve(this);
// }, this, RES.ResourceItem.TYPE_SHEET);
// });
// }
\ No newline at end of file
import { ModuleTypes } from "../types/sceneTypes";
import Scene from "../components/Scene";
import Loading from "../components/Loading";
export default class SceneCtrl {
private _parent: egret.Sprite;
private _currentScene: Scene;
private _mask: egret.Sprite;
static _instance: SceneCtrl;
static get instance() {
......@@ -12,18 +14,42 @@ export default class SceneCtrl {
this._parent = parent;
}
change(type: ModuleTypes) {
change(type: ModuleTypes, data?) {
const cls = this._sceneClassMap[type];
const scene: Scene = new cls();
if (!window['development']) {
Loading.instace.show();
RES.getResByUrl(`${scene.skinKey.toLowerCase()}_json`, (sheet: egret.SpriteSheet) => {
Loading.instace.hide();
this.showAfterLoadAtlas(scene, data);
}, this, RES.ResourceItem.TYPE_SHEET);
} else {
this.showAfterLoadAtlas(scene, data);
}
}
showAfterLoadAtlas(scene: Scene, data) {
if (this._currentScene) {
this._currentScene.destroy();
this._parent.removeChild(this._currentScene);
}
const cls = this._sceneClassMap[type];
const scene: Scene = new cls();
scene.loadSkin();
scene.start();
this.addToStage(scene);
}
addMask() {
if (!this._mask) {
this._mask = new egret.Sprite();
this._mask.touchEnabled = true;
this._mask.graphics.beginFill(0, .7);
this._mask.graphics.drawRect(0, 0, 750, 1624);
this._mask.graphics.endFill();
}
this._mask.alpha = 1;
this._parent.addChild(this._mask);
}
private addToStage(scene: Scene) {
this._currentScene = scene;
this._parent.addChild(scene);
......
......@@ -2,16 +2,31 @@ class Layers extends eui.UILayer {
private _topLayer: egret.Sprite;
private _popupLayer: egret.Sprite;
private _sceneLayer: egret.Sprite;
private _bottomLayer: egret.Sprite;
init(root: eui.UILayer) {
root.addChild(this);
this._topLayer = new egret.Sprite();
this._popupLayer = new egret.Sprite();
this._sceneLayer = new egret.Sprite();
this._bottomLayer = new egret.Sprite();
this.addChild(this._bottomLayer);
this.addChild(this._sceneLayer);
this.addChild(this._popupLayer);
this.addChild(this._topLayer);
}
_bg: egret.Bitmap;
addFirstBackground(bitmap: egret.Bitmap): any {
this._bg = bitmap;
this._bottomLayer.addChild(bitmap);
}
removeFirstBackground(): any {
if (this._bg)
this._bottomLayer.removeChild(this._bg);
this._bg = null;
}
get topLayer() { return this._topLayer }
get popupLayer() { return this._popupLayer }
get sceneLayer() { return this._sceneLayer }
......
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