unlocking zooming with a delay when entering / leaving focusable zone

This commit is contained in:
Hanusiak Piotr 2022-01-12 12:08:11 +01:00
parent 3f3f488924
commit 58af1f05f7
3 changed files with 19 additions and 6 deletions

View file

@ -19,10 +19,12 @@ export class CameraManager extends Phaser.Events.EventEmitter {
private cameraMode: CameraMode = CameraMode.Free;
private cameraLockedDelayedCall: Phaser.Time.TimerEvent | undefined;
private restoreZoomTween?: Phaser.Tweens.Tween;
private startFollowTween?: Phaser.Tweens.Tween;
private cameraFollowTarget?: { x: number; y: number };
private cameraLocked: boolean;
constructor(scene: GameScene, cameraBounds: { x: number; y: number }, waScaleManager: WaScaleManager) {
super();
@ -30,6 +32,7 @@ export class CameraManager extends Phaser.Events.EventEmitter {
this.camera = scene.cameras.main;
this.cameraBounds = cameraBounds;
this.cameraLocked = false;
this.waScaleManager = waScaleManager;
@ -56,6 +59,8 @@ export class CameraManager extends Phaser.Events.EventEmitter {
this.waScaleManager.saveZoom();
this.waScaleManager.setFocusTarget(focusOn);
this.cameraLocked = true;
this.unlockCameraWithDelay(duration);
this.restoreZoomTween?.stop();
this.startFollowTween?.stop();
const marginMult = 1 + margin;
@ -79,10 +84,12 @@ export class CameraManager extends Phaser.Events.EventEmitter {
);
}
public leaveFocusMode(player: Player): void {
public leaveFocusMode(player: Player, duration = 0): void {
this.cameraLocked = false;
this.waScaleManager.setFocusTarget();
this.startFollow(player, 1000);
this.restoreZoom(1000);
this.unlockCameraWithDelay(duration);
this.startFollow(player, duration);
this.restoreZoom(duration);
}
public startFollow(target: object | Phaser.GameObjects.GameObject, duration: number = 0): void {
@ -132,7 +139,13 @@ export class CameraManager extends Phaser.Events.EventEmitter {
}
public isCameraLocked(): boolean {
return this.cameraMode === CameraMode.Focus;
return this.cameraLocked;
}
private unlockCameraWithDelay(delay: number): void {
this.scene.time.delayedCall(delay, () => {
this.cameraLocked = false;
});
}
private setCameraMode(mode: CameraMode): void {

View file

@ -855,7 +855,7 @@ export class GameScene extends DirtyScene {
for (const zone of zones) {
const focusable = zone.properties?.find((property) => property.name === "focusable");
if (focusable && focusable.value === true) {
this.cameraManager.leaveFocusMode(this.CurrentPlayer);
this.cameraManager.leaveFocusMode(this.CurrentPlayer, 1000);
break;
}
}

View file

@ -162,7 +162,7 @@
{
"name":"zoom_margin",
"type":"float",
"value":3
"value":0
}],
"rotation":0,
"type":"zone",