fix: HUD elements no longer shift when zooming in/out

setScrollFactor(0) prevents camera scroll but NOT zoom displacement.
Added fixToScreen() utility that compensates object positions and scale
each frame based on current camera zoom. Applied to all scrollFactor(0)
UI elements in GameScene, Minimap, and BossArenaScene.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Денис Шкабатур
2026-02-12 18:22:40 +03:00
parent 6ba0746bb9
commit 1b2cc0cd86
4 changed files with 65 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
import Phaser from 'phaser';
import type { TileData, TileGrid, WorldData } from './types';
import { fixToScreen } from '../ui/screen-fix';
const MINIMAP_DEPTH = 100;
const VIEWPORT_DEPTH = 101;
@@ -102,8 +103,17 @@ export class Minimap {
/** Update the viewport indicator rectangle — call each frame */
update(camera: Phaser.Cameras.Scene2D.Camera): void {
// Compensate for camera zoom on all minimap elements.
// Graphics objects (border, viewport) use (0,0) as origin so their
// local draw coordinates map 1:1 to screen pixels after compensation.
fixToScreen(this.border, 0, 0, camera);
fixToScreen(this.viewport, 0, 0, camera);
// Image has origin(1,0): position = top-right corner
const screenW = camera.width;
const padding = 10;
fixToScreen(this.image, screenW - padding, padding, camera);
const minimapW = this.mapWidth * this.minimapScale;
const minimapX = screenW - padding - minimapW;
const minimapY = padding;