新增事件发送接收器
This commit is contained in:
@@ -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");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
3
demo/src/game/CoreEmitterType.ts
Normal file
3
demo/src/game/CoreEmitterType.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
enum CoreEmitterType {
|
||||
Update,
|
||||
}
|
||||
@@ -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() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user