This commit is contained in:
Hanusiak Piotr 2021-12-07 13:18:36 +01:00
parent b00d24dbf7
commit 29ccb52c93
3 changed files with 20 additions and 12 deletions

View file

@ -32,13 +32,12 @@ export class CameraManager extends Phaser.Events.EventEmitter {
this.initCamera();
this.scene.game.events.on("wa-scale-manager:refresh-focus-on-target", () => {
const focusOn = this.waScaleManager.getFocusTarget();
if (!focusOn) {
return;
}
this.camera.centerOn(focusOn.x + focusOn.width * 0.5, focusOn.y + focusOn.height * 0.5);
});
this.bindEventHandlers();
}
public destroy(): void {
this.scene.game.events.off("wa-scale-manager:refresh-focus-on-target");
super.destroy();
}
public getCamera(): Phaser.Cameras.Scene2D.Camera {
@ -128,4 +127,16 @@ export class CameraManager extends Phaser.Events.EventEmitter {
this.camera = this.scene.cameras.main;
this.camera.setBounds(0, 0, this.cameraBounds.x, this.cameraBounds.y);
}
private bindEventHandlers(): void {
this.scene.game.events.on(
"wa-scale-manager:refresh-focus-on-target",
(focusOn: { x: number; y: number; width: number; height: number }) => {
if (!focusOn) {
return;
}
this.camera.centerOn(focusOn.x + focusOn.width * 0.5, focusOn.y + focusOn.height * 0.5);
}
);
}
}