Orientation change doesn't get detected

I’m having issues with orientation change detection in Phaser 3.

scene.scale.on('orientationchange', function(orientation) {
    // this doesn't get called on mobile...
});

The function above fires when playing on desktop browsers with dev tools simulating mobile devices. Rotate is detected just fine.

However, on mobile devices, it never got called.
Is this a bug? Is there any other way to detect orientation?

Hi
have you seen this example? looks working well on my mobile device

Hi @Darko,

Thank you for your answer.
That’s weird… that example didn’t work on my mobile devices either.
As stated here, it seems to be a bug indeed.
That page also referred to your example.

I have found a solution though.

window.onresize = function (){
   if(window.innerWidth > window.innerHeight){
     // landscape
   }
   else{
     // portrait
   }
};

Now it works well across all my devices.

3 Likes

Keep in mind that window.innerWidth and windor.InnerHeight might not be the same when changing the orientation, ex: on chrome on iOS then you have to use the outherWidth instead of inner

Sorry for digging this old topic, but it is still present!
On iphone (e.g. on my iPhone 11, iOS15) the “orientationchange” is detected, but the calculation of “this.scale.orientation === Phaser.Scale.PORTRAIT” is wrong.
If i rotate from portait to landscape, it starts my notification for “please use your device in landscape”
User have to reload the page in landscape mode, to prevent this behavior.
Tested on the official example for orientation, same result:

So, only change right now is to implement the here mentioned custom check on window.resize i belive.