[API] Grid camera default to top-left + center_camera() method #169

Closed
opened 2025-12-31 21:18:18 +00:00 by adjutant · 0 comments

Summary

Change Grid's default camera position so tile (0,0) appears at the top-left corner of the widget, and add a center_camera() convenience method.

Current Behavior

Grid camera defaults to (0,0), which places the center of the view at pixel (0,0). Result: 3/4 of the view is black (negative coordinates with no tiles).

Proposed Behavior

1. Default Camera Position

Calculate initial center so that tile (0,0) is at top-left corner of grid widget:

center_x = (widget_width / tile_size) / 2
center_y = (widget_height / tile_size) / 2

2. center_camera() Method

# Center on grid's tile center
grid.center_camera()

# Center on specific tile (integers)
grid.center_camera((5, 10))

# Center on fractional position (0.5, 0.5 = middle of tile 0,0)
grid.center_camera((0.5, 0.5))

Implementation Notes

  • Must not interfere with .center property animation
  • Float coordinates allow smooth camera positioning
  • Default (no args) centers on (grid_width/2, grid_height/2)

Rationale

  • Top-left default matches UI coordinate conventions
  • Player typically spawns near (0,0) - now visible immediately
  • center_camera() provides easy "show whole dungeon" behavior
  • Float support enables fancy camera tricks

🤖 Generated with Claude Code

## Summary Change Grid's default camera position so tile (0,0) appears at the top-left corner of the widget, and add a `center_camera()` convenience method. ## Current Behavior Grid camera defaults to (0,0), which places the *center* of the view at pixel (0,0). Result: 3/4 of the view is black (negative coordinates with no tiles). ## Proposed Behavior ### 1. Default Camera Position Calculate initial center so that tile (0,0) is at top-left corner of grid widget: ``` center_x = (widget_width / tile_size) / 2 center_y = (widget_height / tile_size) / 2 ``` ### 2. `center_camera()` Method ```python # Center on grid's tile center grid.center_camera() # Center on specific tile (integers) grid.center_camera((5, 10)) # Center on fractional position (0.5, 0.5 = middle of tile 0,0) grid.center_camera((0.5, 0.5)) ``` ### Implementation Notes - Must not interfere with `.center` property animation - Float coordinates allow smooth camera positioning - Default (no args) centers on `(grid_width/2, grid_height/2)` ## Rationale - Top-left default matches UI coordinate conventions - Player typically spawns near (0,0) - now visible immediately - `center_camera()` provides easy "show whole dungeon" behavior - Float support enables fancy camera tricks 🤖 Generated with [Claude Code](https://claude.com/claude-code)
john closed this issue 2026-01-01 20:31:37 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
john/McRogueFace#169
No description provided.