Skip to content

Improve canvas resize handling (partial fix for #88 and #59)#111

Open
itsthisjustin wants to merge 3 commits intoDavidobot:masterfrom
itsthisjustin:fix/canvas-resize-improvements
Open

Improve canvas resize handling (partial fix for #88 and #59)#111
itsthisjustin wants to merge 3 commits intoDavidobot:masterfrom
itsthisjustin:fix/canvas-resize-improvements

Conversation

@itsthisjustin
Copy link

Summary

This PR adds partial support for canvas resizing in response to browser window size changes, addressing the limitations described in issues #88 and #59.

Changes Made

JavaScript (index.html - both release and compat)

  • Added resizeCanvas() function that monitors and responds to canvas size changes
  • Updates canvas element dimensions when the browser window resizes
  • Attempts to trigger SDL resize events to notify the LÖVE engine
  • Handles window resize events, fullscreen changes, and includes periodic checking

CSS (love.css - both release and compat)

  • Made canvas responsive with max-width: 100% and max-height: 100vh
  • Maintains aspect ratio while adapting to window size
  • Prevents content cutoff on window resize

Documentation (readme.md)

What This Fixes

✅ Canvas element no longer cuts off content when window resizes
✅ Better responsive behavior for different screen sizes
✅ Improved fullscreen handling
✅ Canvas adapts to browser window size changes

Known Limitations

This is a partial fix that improves the current behavior but doesn't fully resolve the underlying limitation:

  • ⚠️ Game content renders at the size specified in conf.lua (e.g., 1280x720)
  • ⚠️ Canvas element resizes, but the game's internal viewport doesn't scale to fill it
  • ⚠️ love.window.setMode() from game code still won't dynamically resize the canvas
  • ⚠️ love.resize() callback may not be triggered on canvas size changes

These remaining limitations exist because SDL/Emscripten in the current LÖVE build doesn't properly handle dynamic canvas resizing without deeper engine-level modifications.

Why This Approach?

A complete fix would require:

  1. Modifying the LÖVE engine's SDL/Emscripten integration
  2. Adding emscripten_set_canvas_element_size() calls to the window module
  3. Rebuilding the LÖVE binaries with these changes

This PR provides immediate value by fixing the "content cutoff" issue while being honest about what still needs engine-level work.

Testing

Tested with a production game (Knave) deployed to Cloudflare Pages. The canvas now properly resizes with the browser window instead of cutting off content.

Backwards Compatibility

✅ Fully backwards compatible - existing games will work exactly as before, but will now handle window resizing better.

Related Issues


🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

itsthisjustin and others added 3 commits October 6, 2025 15:44
This commit adds partial support for canvas resizing in response to browser
window size changes, addressing issues Davidobot#88 and Davidobot#59.

## Changes:

**JavaScript (index.html):**
- Added resizeCanvas() function that monitors canvas size changes
- Updates canvas element dimensions when browser window resizes
- Triggers SDL resize events to notify the engine
- Handles window resize, fullscreen changes, and periodic checks

**CSS (love.css):**
- Made canvas responsive with max-width: 100% and max-height: 100vh
- Maintains aspect ratio while adapting to window size

**Documentation (readme.md):**
- Added comprehensive note about canvas resizing (Note Davidobot#9)
- Clearly documents current limitations
- Explains that game viewport doesn't scale (engine limitation)
- References upstream issues Davidobot#88 and Davidobot#59

## What This Fixes:
✅ Canvas element no longer cuts off when window resizes
✅ Better responsive behavior for different screen sizes
✅ Improved fullscreen handling

## Known Limitations:
- Game content renders at size specified in conf.lua
- Canvas resizes but game viewport doesn't scale to fill it
- love.window.setMode() from game code still won't work
- love.resize() callback may not be triggered

These limitations would require engine-level changes to SDL/Emscripten
integration to fully resolve.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Fixed goFullScreen() to use correct API method names (requestFullscreen vs requestFullScreen)
- Added mobile device detection to use CSS-based fullscreen on mobile (more reliable than Fullscreen API)
- Auto-fullscreen on mobile devices when game finishes loading
- Desktop browsers continue to use native Fullscreen API
- Updated all HTML templates (release, compat, sample)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Made all UI elements (header, footer, canvas, loading screen) fully responsive
- Added CSS media queries for mobile devices (768px and 480px breakpoints)
- Fixed desktop fullscreen to hide header via CSS :fullscreen pseudo-class
- Fixed mobile fullscreen to properly fill 100vh by:
  - Setting actual canvas buffer dimensions to window.innerWidth/innerHeight
  - Removing all CSS max-width/max-height constraints (set to 'none')
  - Hiding footer and header elements
  - Setting body background to black to prevent color bleed-through
- Loading screen now scales dynamically based on container width
- Footer is now fixed at bottom and centered on all devices

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@itsthisjustin
Copy link
Author

Additional Changes - Mobile Responsive Design

Added comprehensive mobile responsive design and fullscreen improvements:

Mobile Responsiveness

  • ✅ All UI elements (header, footer, canvas, loading screen) now scale properly on mobile devices
  • ✅ Added CSS media queries for tablets (≤768px) and phones (≤480px)
  • ✅ Loading screen dynamically sizes based on container width with responsive fonts
  • ✅ Footer is now fixed, full-width, and centered on all screen sizes

Fullscreen Improvements

Desktop:

  • ✅ Header now automatically hides when entering fullscreen mode (using CSS :fullscreen pseudo-class)

Mobile:

  • ✅ Canvas now properly fills 100vh by setting actual canvas buffer dimensions to window.innerWidth x window.innerHeight
  • ✅ Removed all CSS constraints by setting maxWidth/maxHeight to none
  • ✅ Footer and header are hidden when in fullscreen
  • ✅ Body background set to black to prevent color bleed-through
  • ✅ Canvas truly takes up entire screen without gaps or bars

These changes ensure a seamless fullscreen experience across all devices while maintaining proper mobile responsiveness when not in fullscreen mode.

@itsthisjustin itsthisjustin force-pushed the fix/canvas-resize-improvements branch from 9832b3b to c76c5f5 Compare October 7, 2025 02:24
@itsthisjustin
Copy link
Author

Sorry did not mean to push that mobile keyboard support thing. Stupid claude was way too eager there. I've reverted it.

@itsthisjustin
Copy link
Author

Also if anyone wants to test how this works, I've built my game with it at https://playknave.com (try opening this on your phone)

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.

resolution resizing issue love.resize is not called when changing the size of the love.js canvas

1 participant