Skip to content

Added useSafeArea setting for mobile targets#20

Draft
nateboxer wants to merge 5 commits into
Oval-Tutu:mainfrom
nateboxer:safe_area
Draft

Added useSafeArea setting for mobile targets#20
nateboxer wants to merge 5 commits into
Oval-Tutu:mainfrom
nateboxer:safe_area

Conversation

@nateboxer

Copy link
Copy Markdown

Added useSafeArea (optional, use window safe area for mobile target instead of getDimensions()), safe_offset_x, safe_offset_y to state. WIP - this correctly sizes the viewport but does not center it correctly or use the safe offset values.

I attempted to modify the existing offset_y property but that seems to be used for something different than I expected. I also attempted to apply the offsets to all the love.graphics.draw() commands, but that seemed to have no effect.

I could use some advice from the original author as to where I might apply a horizontal and vertical offsets.

…nstead of getDimensions()), safe_offset_x, safe_offset_y to state. WIP - this correctly sizes the viewport but does not center it corr

ectly or use the safe offset values.
@nateboxer nateboxer marked this pull request as draft April 7, 2025 16:55
@nateboxer

nateboxer commented Apr 7, 2025

Copy link
Copy Markdown
Author

See below - I drew a light orange rectangle around the game (viewport). The scale looks good (takes into account the safe area width and height) but I haven't been able to center it horizontally yet:

Screenshot 2025-04-07 at 9 57 59 AM

Here's how I'm setting up Shove in my game (GAME_W/H is the game window dimension. SAFE_W/H is the safe area window dimension):

shove.setResolution(GAME_W, GAME_H, {fitMethod = "aspect", useSafeArea = true})
shove.setWindowMode(SAFE_W, SAFE_H, {resizable = true})

Mobile safe area is defined as x, y, width, height where x (offset) + width* = actual screen width and y (offset) + height * = actual screen height. (* If there is a device occlusion or overlay on the right or bottom side, they can be calculated by subtracting from the actual screen width and height. You don't need to worry about the right and bottom offsets since the safe area width and height already have subtracted them out.)

To center a canvas inside the safe area, the formula is:

x = safe_offset_x + (scaled_game_width - safe_area_width) / 2
y = safe_offset_y + (scaled_game_height - safe_area_height) / 2

Note: In the case of a desktop window, turning on the useSafeArea option in Shove should have no effect (since x and y offsets will be zero and width and height will equal the screen width and height.

@nateboxer

Copy link
Copy Markdown
Author

I was wondering if by replacing the two places where Shove gets "actual" dimensions, I was hobbling it such that it could not center the viewport. I tried keeping my initial change where state.screen_width and state.screen_height were getting overwritten but commenting out the other two places I replaced getDimensions() with getSafeArea(). It worked mostly. It still doesn't correctly handle the offset for the status bar, but it more or less centers the correctly sized viewport on the screen.

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.

1 participant