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

@@ -48,6 +48,9 @@ import type { MetaState, RunState } from '../run/types';
import { query } from 'bitecs';
import { Projectile } from '../ecs/components';
// UI zoom compensation
import { fixToScreen } from '../ui/screen-fix';
/** Data passed from GameScene to BossArenaScene */
interface BossArenaInitData {
meta: MetaState;
@@ -608,6 +611,13 @@ export class BossArenaScene extends Phaser.Scene {
const cam = this.cameras.main;
const healthPct = this.bossState.health / this.bossState.maxHealth;
// Fix UI positions for camera zoom.
// Graphics at (0,0) — local draw coordinates map 1:1 to screen pixels.
fixToScreen(this.bossHealthBar, 0, 0, cam);
fixToScreen(this.bossHealthText, cam.width / 2, 20, cam);
fixToScreen(this.phaseText, cam.width / 2, 55, cam);
fixToScreen(this.feedbackText, cam.width / 2, cam.height - 60, cam);
// Health bar
const barWidth = 300;
const barHeight = 8;
@@ -679,6 +689,7 @@ export class BossArenaScene extends Phaser.Scene {
victoryText.setScrollFactor(0);
victoryText.setOrigin(0.5);
victoryText.setDepth(200);
fixToScreen(victoryText, cam.width / 2, cam.height / 2, cam);
const methodNames: Record<string, string> = {
chemical: 'Алхимическая победа (NaOH)',

View File

@@ -59,6 +59,9 @@ import {
} from '../run/crisis';
import { getEscalationEffects } from '../run/escalation';
// UI zoom compensation
import { fixToScreen } from '../ui/screen-fix';
// Mycelium imports
import { FungalNode } from '../ecs/components';
import { spawnFungalNodes } from '../mycelium/nodes';
@@ -623,6 +626,16 @@ export class GameScene extends Phaser.Scene {
} else {
this.phaseText.setColor('#00ff88');
}
// Fix UI element positions for current camera zoom.
// setScrollFactor(0) prevents scroll but NOT zoom displacement.
const cam = this.cameras.main;
fixToScreen(this.statsText, 10, 30, cam);
fixToScreen(this.interactionText, cam.width / 2, cam.height - 40, cam);
fixToScreen(this.phaseText, cam.width / 2, 12, cam);
fixToScreen(this.memoryFlashText, cam.width / 2, cam.height / 2, cam);
fixToScreen(this.crisisOverlay, cam.width / 2, cam.height / 2, cam);
fixToScreen(this.mycosisOverlay, cam.width / 2, cam.height / 2, cam);
}
/** Find the nearest fungal node within interaction range, or null */