From 1fa03e44df81d07ed34c10168025786aace7ec19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 14 Jun 2021 18:40:58 +0200 Subject: [PATCH 1/2] Fixing size of camera on resize The size of the Camera after a change in zoom is only computed on the "render" step. Therefore, we should wait the "render" step to call GameScene.onResize. Closes #1180 --- front/src/Phaser/Services/WaScaleManager.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/front/src/Phaser/Services/WaScaleManager.ts b/front/src/Phaser/Services/WaScaleManager.ts index acbecc38..1fa46e4f 100644 --- a/front/src/Phaser/Services/WaScaleManager.ts +++ b/front/src/Phaser/Services/WaScaleManager.ts @@ -3,6 +3,7 @@ import ScaleManager = Phaser.Scale.ScaleManager; import {coWebsiteManager} from "../../WebRtc/CoWebsiteManager"; import type {Game} from "../Game/Game"; import {ResizableScene} from "../Login/ResizableScene"; +import * as Phaser from "phaser"; class WaScaleManager { @@ -39,10 +40,11 @@ class WaScaleManager { const style = this.scaleManager.canvas.style; style.width = Math.ceil(realSize.width / devicePixelRatio) + 'px'; style.height = Math.ceil(realSize.height / devicePixelRatio) + 'px'; - // Note: onResize will be called twice (once here and once is Game.ts), but we have no better way. + // Note: onResize will be called twice (once here and once in Game.ts), but we have no better way. for (const scene of this.game.scene.getScenes(true)) { if (scene instanceof ResizableScene) { - scene.onResize(); + // We are delaying the call to the "render" event because otherwise, the "camera" coordinates are not correctly updated. + scene.events.once(Phaser.Scenes.Events.RENDER, () => scene.onResize()); } } From 6bca3469b6469ba4576644e49e5ef9d32ebb8354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 14 Jun 2021 18:44:20 +0200 Subject: [PATCH 2/2] Removing useless import --- front/src/Phaser/Services/WaScaleManager.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/front/src/Phaser/Services/WaScaleManager.ts b/front/src/Phaser/Services/WaScaleManager.ts index 1fa46e4f..1da0fcf3 100644 --- a/front/src/Phaser/Services/WaScaleManager.ts +++ b/front/src/Phaser/Services/WaScaleManager.ts @@ -3,7 +3,6 @@ import ScaleManager = Phaser.Scale.ScaleManager; import {coWebsiteManager} from "../../WebRtc/CoWebsiteManager"; import type {Game} from "../Game/Game"; import {ResizableScene} from "../Login/ResizableScene"; -import * as Phaser from "phaser"; class WaScaleManager {