新增事件发送接收器

This commit is contained in:
yhh
2020-06-15 12:16:23 +08:00
parent 16892eb7af
commit c3120d791f
15 changed files with 141 additions and 123 deletions

View File

@@ -29,6 +29,7 @@
class Main extends eui.UILayer {
public static emitter: Emitter<CoreEmitterType>;
protected createChildren(): void {
super.createChildren();
@@ -51,10 +52,15 @@ class Main extends eui.UILayer {
egret.registerImplementation("eui.IAssetAdapter", assetAdapter);
egret.registerImplementation("eui.IThemeAdapter", new ThemeAdapter());
Main.emitter = new Emitter<CoreEmitterType>();
this.addEventListener(egret.Event.ENTER_FRAME, this.updateFrame, this);
this.runGame();
}
private updateFrame(evt: egret.Event){
Main.emitter.emit(CoreEmitterType.Update, evt);
}
private async runGame() {
await this.loadResource();
this.createGameScene();
@@ -98,8 +104,11 @@ class Main extends eui.UILayer {
new Vector2(10, 10),
new Vector2(0, 10),
new Vector2(0, 0)]));
player.addComponent(new VerletDemo());
player.addComponent(new SpawnComponent(EnemyType.worm));
// console.log(player.transform.position);
Main.emitter.addObserver(CoreEmitterType.Update, ()=>{
console.log("update emitter");
});
}
}

View File

@@ -0,0 +1,3 @@
enum CoreEmitterType {
Update,
}

View File

@@ -1,29 +0,0 @@
class VerletDemo extends RenderableComponent {
private _world: VerletWorld;
private _stage: egret.Stage;
protected getWidth(){
return this.entity.scene.stage.stageWidth;
}
protected getHeight(){
return this.entity.scene.stage.stageHeight;
}
public onAddedToEntity(){
this._stage = this.entity.scene.stage;
this._world = new VerletWorld(new Rectangle(0, 0, this.width, this.height));
this._world.addComposite(new Box(new Vector2(100, 100), 50, 20));
this._world.addComposite(new Box(new Vector2(10, 10), 200, 100));
}
public update(){
this._world.update();
this._world.debugRender(this._stage);
}
initialize() {
}
}