From 9763b4b37495f4d06861b1834195a03b0fdeb5ea Mon Sep 17 00:00:00 2001 From: Natalie Date: Sun, 10 May 2026 04:08:59 -0700 Subject: [PATCH] =?UTF-8?q?feat(@projects/@magic-civilization):=20?= =?UTF-8?q?=E2=9C=A8=20improve=20camera=20centering=20precision?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- .../scenes/tests/full_game_demo_proof.gd | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/game/engine/scenes/tests/full_game_demo_proof.gd b/src/game/engine/scenes/tests/full_game_demo_proof.gd index c080f0b0..77aebdd6 100644 --- a/src/game/engine/scenes/tests/full_game_demo_proof.gd +++ b/src/game/engine/scenes/tests/full_game_demo_proof.gd @@ -112,18 +112,30 @@ func _ready() -> void: elif cities.has_method("render_cities"): cities.call("render_cities") - # Camera centred on the map middle, zoomed out enough to see the - # whole continent. + # Camera centred on the actual pixel-bbox of the rendered tiles. The + # axial→pixel transform isn't a simple linear scale (flat-top hex offset + # rows) so compute the bounding box from the real tile positions. + var min_p: Vector2 = Vector2(INF, INF) + var max_p: Vector2 = Vector2(-INF, -INF) + for pos_key: Vector2i in game_map.tiles: + var p: Vector2 = HexUtilsScript.axial_to_pixel(pos_key) + min_p = min_p.min(p) + max_p = max_p.max(p) + var bbox: Vector2 = max_p - min_p + var center: Vector2 = (min_p + max_p) * 0.5 + # Fit the longer axis into the viewport with 5% padding. + var pad: float = 1.10 + var fit_x: float = (bbox.x * pad) / float(VIEWPORT_SIZE.x) + var fit_y: float = (bbox.y * pad) / float(VIEWPORT_SIZE.y) + var world_per_screen: float = max(fit_x, fit_y) + var zoom_factor: float = 1.0 / max(world_per_screen, 0.001) var cam: Camera2D = Camera2D.new() cam.name = "DemoCamera" - var mid_axial: Vector2i = Vector2i(game_map.width / 2, game_map.height / 2) - var mid_pixel: Vector2 = HexUtilsScript.axial_to_pixel(mid_axial) - cam.position = mid_pixel - # axial_to_pixel scales each tile to ~150px; duel map (40×24) = ~6000×3600 px. - # Zoom 0.18 fits the whole map into 1920×1080. - cam.zoom = Vector2(0.18, 0.18) + cam.position = center + cam.zoom = Vector2(zoom_factor, zoom_factor) cam.make_current() add_child(cam) + print("full_game_demo: bbox=%s center=%s zoom=%.4f" % [bbox, center, zoom_factor]) # Wait for the renderers to flush their _draw passes. for _i: int in range(20):