86 Camera Bounds Clamping. 86 of 95.
86/CAMERA BEHAVIOR/86 of 95
Camera Bounds Clamping
Pan and zoom should stop at the world edge.
Best experienced with a pointer.
The problem
Panning past the content leaves the viewport mostly empty, so orientation is lost in blank space.
The solution
Bounds clamping keeps the viewport filled; when the world fits, pan centers instead of freezing on an inverted range.
Experiment
Play with the values
20px
1
How it works
- The world has explicit bounds; the camera is not free to pan into empty space.
- A pan delta is applied as a proposed translation.
- The viewport rectangle is computed in world coordinates after that proposal.
- If the world is smaller than the view, the content is centered instead of clamping an inverted range.
- Otherwise translation is clamped so the viewport stays filled up to the world edge.
Seen in
Map pans
Tile maps stop at the edge of available coverage instead of infinite gray void.
Image viewers
Zoomed photos clamp so a corner of the image always remains on screen.
Board canvases
Project boards keep the camera within a soft world rect around frames.
Game cameras
Side-scrollers clamp the camera so the player cannot look past level geometry.