Detect mobile and switch to landscape

How do I…

I am trying to have Gdevelop switch to landscape depending on if the device I’m using is mobile or not. I have searched for a solution and I have changed my settings to what I think should solve my problem:

Screenshot 2025-01-13 093312

What is the expected result

I am expecting the game to be landscape when run on mobile.

What is the actual result

I launched the editor on my mobile device, and make sure the game properties are set up:


And try to preview the level but it’s not in landscape. It’s in portrait as the screenshot demonstrates.

I know that the flag for is a mobile device is on because on my title screen i had to add this logic otherwise I couldn’t tap on a button that I previously was able to click on:

Is there something super obvious that I’m missing?

Yes. Your actions about setting the screen size and the resolution are messing it up. For instance I can make a mobile game with Landscape in the properties. Now it should only run in landscape, but I can add 2 simple events in my game that now cause my game to change orientation when the user rotates the device. More annoyingly (for the user), this will happen whether they have the device orientation set to change orientation when they rotate the device or not.

Do you need it to run in Landscape only if the device is mobile, but portrait mode if the device is not mobile? Is it meant to play in portrait mode on the pc?

Edit as a thought occurred: so you’re using the preview? Maybe that’s the problem too, it is in Landscape but since you’re in a preview and not a build, you’re just not seeing the whole view. Did you rotate your device?

This is slightly embarrassing: My rotation was locked on my phone for portrait. I was expecting the engine to force landscape :sweat_smile:.

Sorry :bowing_man:

2 Likes

No that’s great news! It means no bug to fix in your game!