Skip to content

Fix world_to_screen to handle viewport correctly#1017

Merged
not-fl3 merged 1 commit into
not-fl3:masterfrom
ESBL-Erik:fix-world-to-screen-viewport
Feb 3, 2026
Merged

Fix world_to_screen to handle viewport correctly#1017
not-fl3 merged 1 commit into
not-fl3:masterfrom
ESBL-Erik:fix-world-to-screen-viewport

Conversation

@ESBL-Erik

Copy link
Copy Markdown
Contributor

Problem

screen_to_world correctly accounts for viewport position and size, but world_to_screen always maps to full screen coordinates, ignoring any viewport setting. This makes the two methods non-symmetric when a viewport is set.

Solution

Added the same viewport handling to world_to_screen that screen_to_world already has, making them proper inverses of each other.

Testing

Tested with a Camera2D using a viewport with margins (not at origin). Labels positioned using world_to_screen now correctly appear within the viewport region and track world objects properly during pan/zoom.

The screen_to_world method correctly accounts for viewport position and
size, but world_to_screen was always mapping to full screen coordinates,
ignoring any viewport setting. This made the two methods non-symmetric
when a viewport was set.

This fix adds the same viewport handling to world_to_screen that
screen_to_world already has, making them proper inverses of each other.
@not-fl3

not-fl3 commented Feb 3, 2026

Copy link
Copy Markdown
Owner

Thanks for PR!

@not-fl3 not-fl3 merged commit aec10b2 into not-fl3:master Feb 3, 2026
6 checks passed
@ESBL-Erik ESBL-Erik deleted the fix-world-to-screen-viewport branch February 4, 2026 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants