Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When refreshing the window the minwidth and minheight is used sometimes #16

Closed
Sheepolution opened this issue Oct 21, 2020 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@Sheepolution
Copy link

Sheepolution commented Oct 21, 2020

Tested this mainly on Chrome, but I believe this happened on Firefox as well.
Happens with both release and compat version.

This is my conf.lua:

function love.conf(t)
	t.window.width =  500
	t.window.height = 500
	t.window.minwidth = 100
	t.window.minheight = 100
end
  1. I have a game with
  2. I build my game using love.js.
  3. I open the game in browser. It looks fine.
  4. I refresh the page a few times. Here's the bug: Sometimes when refreshing the game will use the minwidth and minheight, instead of the set width and height.

It does not matter if t.window.resizable is true or not.

@Davidobot Davidobot added the bug Something isn't working label Oct 22, 2020
@Davidobot
Copy link
Owner

Davidobot commented Oct 22, 2020

Huh! This may be related to times when the game window just doesn't show up randomly. Good spot.

Probably a race condition on window initialisation between SDL and the JS.

EDIT: as described here: https://love2d.org/forums/viewtopic.php?f=12&t=81736&start=140#p235945

@kraybit
Copy link

kraybit commented Nov 23, 2020

I have seen the same behavior, and perhaps found something interesting.

We tried changing the way the canvas is shown once the loading is done. Instead of changing the canvas' style from display: none to display: block, we changed all that so the canvas starts with visibility: hidden and then change that to visibility: visible. (I'm typing from memory, don't quite remember the exact CSS/JavaScript here, but the main idea is there).

To be clear, the canvas always has display: block set, only visibility changes.

That seems to make a difference. Worth a try?

@rameshvarun
Copy link

rameshvarun commented Apr 13, 2021

I was able to fix these problems using a couple changes in order to create a fully responsive game that fills the screen on both desktop and mobile.

  1. Use visibility instead of display to show the canvas.

As @kraybit suggested, I used the following properties on the canvas: visibility: hidden; display: block; plus updating the setStatus function.

setStatus: function(text) {
  if (text) {
    drawLoadingText(text);
  } else if (Module.remainingDependencies === 0) {
    document.getElementById('loadingCanvas').style.display = 'none';
    document.getElementById('canvas').style.visibility = 'visible';
  }
},
  1. Set minwidth and minheight in conf.lua to a square ratio
 t.window.minwidth = 100
 t.window.minheight = 100

I can't explain why this has to be a square ratio, but without it the image was distorted on mobile.

  1. Make canvas stretch to the full screen.

I put the following properties on my canvas to make it cover the screen. position: absolute; left: 0px; top: 0px; width: 100%; height: 100%; This automatically invokes love.resize on window size changes, likely by way of emscripten's integration with SDL.

  1. Update viewport meta tag

<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, minimum-scale=1, maximum-scale=1">

I had to make some changes to the viewport meta tag. Again, not 100% what the logic of this change is, but without it the image was improperly scaled on mobile.

This is my index file.

Davidobot added a commit that referenced this issue Apr 13, 2021
   canvas-appearing behaviour. Seems to break resizing love callback
   unless special canvas properties are set (see issue)
 - better error reporting
 - websocket API support (in theory?)
@Davidobot
Copy link
Owner

Assuming solved but will pin as useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants