class Main extends eui.UILayer {
public constructor() {
super();
this.once(egret.Event.ADDED_TO_STAGE, this.addToStage, this);
}
private addToStage() {
Game.init(this.stage);
egret.startTick(this.tickLoop, this);
}
tickLoop(timeStamp:number):boolean{
return false;
}
}
class Game{
static I : Game;
static mainStage: egret.Stage;
static height: number;
static width: number;
static init(stage:egret.Stage) {
Game.I = this;
Game.height = egret.MainContext.instance.stage.stageHeight;
Game.width = egret.MainContext.instance.stage.stageWidth;
Game.mainStage = stage;
/* メソッドなどを記入*/
new GameStage();
new Background();
new Rect();
}
}
class GameStage extends egret.DisplayObjectContainer{
static display : egret.DisplayObjectContainer = null;
constructor(){
super();
this.initial();
}
initial(){
GameStage.display = new egret.DisplayObjectContainer();
Game.mainStage.addChild(GameStage.display);
}
}
class GameObject extends egret.DisplayObjectContainer{
object: egret.DisplayObjectContainer = null;
static objects: GameObject[] = [];
constructor(){
super();
this.initial();
}
initial(){
this.object = new egret.DisplayObjectContainer();
GameStage.display.addChild(this.object);
GameObject.objects.push(this);
}
}
class Rect extends GameObject{
constructor(){
super();
this.method();
}
method(){
//四角形の描画
let rect:egret.Shape = new egret.Shape();
rect.graphics.beginFill(0xeb8a44);
rect.graphics.drawRect(100,0,100,100);
rect.graphics.endFill();
this.object.addChild(rect);
//四角形へのタッチを有効化
this.object.touchEnabled = true;
this.object.addEventListener(egret.TouchEvent.TOUCH_TAP, this.tap, this);
}
tap(){
egret.log("四角形");
}
}
class Background extends GameObject{
constructor(){
super();
this.method();
}
method(){
//四角形の描画
let rect:egret.Shape = new egret.Shape();
rect.graphics.beginFill(0x8eba43);
rect.graphics.drawRect(0,0,Game.width,Game.height);
rect.graphics.endFill();
this.object.addChild(rect);
//四角形へのタッチを有効化
this.object.touchEnabled = true;
this.object.addEventListener(egret.TouchEvent.TOUCH_TAP, this.tap, this);
}
tap(){
egret.log("back");
}
}