Commit 71d6bd0d by Matt

add scenes

parent d31a6fe1
...@@ -29,8 +29,6 @@ ...@@ -29,8 +29,6 @@
class Main extends egret.DisplayObjectContainer { class Main extends egret.DisplayObjectContainer {
public constructor() { public constructor() {
super(); super();
this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this); this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
...@@ -66,7 +64,6 @@ class Main extends egret.DisplayObjectContainer { ...@@ -66,7 +64,6 @@ class Main extends egret.DisplayObjectContainer {
await this.loadResource() await this.loadResource()
this.createGameScene(); this.createGameScene();
const result = await RES.getResAsync("description_json") const result = await RES.getResAsync("description_json")
this.startAnimation(result);
await platform.login(); await platform.login();
const userInfo = await platform.getUserInfo(); const userInfo = await platform.getUserInfo();
console.log(userInfo); console.log(userInfo);
...@@ -86,104 +83,12 @@ class Main extends egret.DisplayObjectContainer { ...@@ -86,104 +83,12 @@ class Main extends egret.DisplayObjectContainer {
} }
} }
private textfield: egret.TextField;
/** /**
* 创建游戏场景 * 创建游戏场景
* Create a game scene * Create a game scene
*/ */
private createGameScene() { private createGameScene() {
let sky = this.createBitmapByName("bg_jpg"); this.addChild(SceneManager.getInstance());
this.addChild(sky);
let stageW = this.stage.stageWidth;
let stageH = this.stage.stageHeight;
sky.width = stageW;
sky.height = stageH;
let topMask = new egret.Shape();
topMask.graphics.beginFill(0x000000, 0.5);
topMask.graphics.drawRect(0, 0, stageW, 172);
topMask.graphics.endFill();
topMask.y = 33;
this.addChild(topMask);
let icon = this.createBitmapByName("egret_icon_png");
this.addChild(icon);
icon.x = 26;
icon.y = 33;
let line = new egret.Shape();
line.graphics.lineStyle(2, 0xffffff);
line.graphics.moveTo(0, 0);
line.graphics.lineTo(0, 117);
line.graphics.endFill();
line.x = 172;
line.y = 61;
this.addChild(line);
let colorLabel = new egret.TextField();
colorLabel.textColor = 0xffffff;
colorLabel.width = stageW - 172;
colorLabel.textAlign = "center";
colorLabel.text = "Hello Egret";
colorLabel.size = 24;
colorLabel.x = 172;
colorLabel.y = 80;
this.addChild(colorLabel);
let textfield = new egret.TextField();
this.addChild(textfield);
textfield.alpha = 0;
textfield.width = stageW - 172;
textfield.textAlign = egret.HorizontalAlign.CENTER;
textfield.size = 24;
textfield.textColor = 0xffffff;
textfield.x = 172;
textfield.y = 135;
this.textfield = textfield;
} }
/**
* 根据name关键字创建一个Bitmap对象。name属性请参考resources/resource.json配置文件的内容。
* Create a Bitmap object according to name keyword.As for the property of name please refer to the configuration file of resources/resource.json.
*/
private createBitmapByName(name: string) {
let result = new egret.Bitmap();
let texture: egret.Texture = RES.getRes(name);
result.texture = texture;
return result;
}
/**
* 描述文件加载成功,开始播放动画
* Description file loading is successful, start to play the animation
*/
private startAnimation(result: string[]) {
let parser = new egret.HtmlTextParser();
let textflowArr = result.map(text => parser.parse(text));
let textfield = this.textfield;
let count = -1;
let change = () => {
count++;
if (count >= textflowArr.length) {
count = 0;
}
let textFlow = textflowArr[count];
// 切换描述内容
// Switch to described content
textfield.textFlow = textFlow;
let tw = egret.Tween.get(textfield);
tw.to({ "alpha": 1 }, 200);
tw.wait(2000);
tw.to({ "alpha": 0 }, 200);
tw.call(change, this);
};
change();
}
} }
\ No newline at end of file
class SceneManager extends egret.DisplayObjectContainer {
// 场景控制器的单例
private static instance: SceneManager;
// 开始场景
private roomScene: RoomScene;
// 游戏场景
private gameScene: GameScene;
public constructor() {
super();
this.init();
}
private init() {
// 实例化两个场景
this.roomScene = new RoomScene();
this.gameScene = new GameScene();
// 默认添加开始场景
this.addChild(this.roomScene);
}
// 实例化单例获取方法
public static getInstance(): SceneManager {
if (!SceneManager.instance) {
SceneManager.instance = new SceneManager();
}
return SceneManager.instance;
}
// 切换场景
public changeScene(type) {
// 释放资源
if (this[type] && typeof this[type].release === 'function') {
this[type].release()
}
// 移除所有显示列表中的对象
this.removeChildren();
// 添加下一个场景
this.addChild(this[type]);
}
}
\ No newline at end of file
class GameScene extends egret.Sprite {
public constructor() {
super();
this.init()
}
// 初始化(给开始按钮绑定点击事件)
private init() {
// put display object to this scene
}
public release() {
// 移除事件
}
}
\ No newline at end of file
class RoomScene extends egret.Sprite {
public constructor() {
super();
this.init()
}
// 初始化(给开始按钮绑定点击事件)
private init() {
console.log('RoomScene.init')
// put display object to this scene
}
public release() {
// 移除事件
}
}
\ No newline at end of file
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