phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
37.11k stars 7.1k forks source link

Scale manager - Orientation misleading #5342

Closed trynx closed 1 year ago

trynx commented 4 years ago

Hi :)

I'm working on a project with phaser 3, and I stumble onto a problem with the platform when checking mobile orientation. The code to check orientation works around 80% of the time, which is very bad for my user case and overall that I can't trust it.

Here is how I check the orientation with the scale manager in my game scene:

console.log(GameOrientation: ${this.scale.orientation}); console.log(Portrait: isPortairt - ${this.scale.isPortrait}, isGamePortrait: ${this.scale.isGamePortrait}); console.log(Landscape: isLandscape - ${this.scale.isLandscape}, isGameLandscape: ${this.scale.isGameLandscape});

        console.log(`H: ${window.innerHeight}, W: ${window.innerWidth}, Orientation: ${window.innerHeight > window.innerWidth ? "portrait" : "landscape"}`);

Phone at portrait

First example: GameOrientation: landscape-primary SantasWildPickGame.ts:358 Portrait: isPortairt - false, isGamePortrait: false SantasWildPickGame.ts:359 Landscape: isLandscape - true, isGameLandscape: true SantasWildPickGame.ts:361 H: 695, W: 412, Orientation: portrait

Second example: GameOrientation: portrait-primary SantasWildPickGame.ts:358 Portrait: isPortairt - true, isGamePortrait: false SantasWildPickGame.ts:359 Landscape: isLandscape - false, isGameLandscape: true SantasWildPickGame.ts:361 H: 695, W: 412, Orientation: portrait

Phone at landscape

GameOrientation: portrait-primary SantasWildPickGame.ts:358 Portrait: isPortairt - true, isGamePortrait: true SantasWildPickGame.ts:359 Landscape: isLandscape - false, isGameLandscape: false SantasWildPickGame.ts:361 H: 332, W: 775, Orientation: landscape

As you see, there is even conflict between internal checks at portrait second example.

Hope this is helpful for future bug fixes and will gladly know if someone else also have this type of bug

Thanks ^^

photonstorm commented 4 years ago

Have you tested this with the latest 3.50 Beta? Because Screen Orientation was updated a lot for that.

trynx commented 4 years ago

Now I tested it with 3.50.0-beta.7 (current last beta version), it's a bit better but still there where false positives :(

Enough for me to do a fast landscape -> portrait -> landscape, and it feels like it brakes it.

Do you want me to provide a short video to see the timings?

There is this.scale.isGamePortrait and this.scale.isGameLandscape, portrait was always false and landscape always true for some reason, at previous version (3.24.1) it was a bit better and they would change the state.

photonstorm commented 4 years ago

If you turn the phone too fast that the browser orientation event doesn't have time to fire, there's nothing you (or Phaser) can do about it.

photonstorm commented 1 year ago

Closing as I believe it's correctly determining orientation when the browser allows it to do so. However, it's quite easy for the browser to miss a rotation if done fast enough, in which case Phaser will miss it also.