From 957ba8f8c7c0072bcd8e9353fb32a8e49b1bbe3e Mon Sep 17 00:00:00 2001 From: Hanusiak Piotr Date: Tue, 7 Dec 2021 17:03:51 +0100 Subject: [PATCH] more subtle start follow player by camera. wip --- front/src/Phaser/Game/CameraManager.ts | 32 +++++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/front/src/Phaser/Game/CameraManager.ts b/front/src/Phaser/Game/CameraManager.ts index c4e4b382..20ce05a4 100644 --- a/front/src/Phaser/Game/CameraManager.ts +++ b/front/src/Phaser/Game/CameraManager.ts @@ -73,13 +73,29 @@ export class CameraManager extends Phaser.Events.EventEmitter { this.waScaleManager.setFocusTarget(); // We are forcing camera.pan to kill previous pan animation on EnterFocusMode this.camera.pan(player.x, player.y, 1, Easing.SineEaseOut, true); - this.startFollow(player); - this.restoreZoom(); + this.startFollow(player, 1000); + this.restoreZoom(1000); } - public startFollow(target: object | Phaser.GameObjects.GameObject): void { + public startFollow(target: object | Phaser.GameObjects.GameObject, duration: number = 0): void { this.setCameraMode(CameraMode.Follow); - this.camera.startFollow(target, true); + if (duration === 0) { + this.camera.startFollow(target, true); + return; + } + // duck typing hack + this.camera.pan( + (target as { x: number; y: number }).x, + (target as { x: number; y: number }).y, + duration, + Easing.Linear, + true, + (camera, progress) => { + if (progress === 1) { + this.camera.startFollow(target, true); + } + } + ); } /** @@ -110,12 +126,16 @@ export class CameraManager extends Phaser.Events.EventEmitter { this.cameraMode = mode; } - private restoreZoom(): void { + private restoreZoom(duration: number = 0): void { + if (duration === 0) { + this.waScaleManager.zoomModifier = this.waScaleManager.getSaveZoom(); + return; + } this.restoreZoomTween?.stop(); this.restoreZoomTween = this.scene.tweens.addCounter({ from: this.waScaleManager.zoomModifier, to: this.waScaleManager.getSaveZoom(), - duration: 1000, + duration, ease: Easing.SineEaseOut, onUpdate: (tween: Phaser.Tweens.Tween) => { this.waScaleManager.zoomModifier = tween.getValue();