Change orientation of the phone in html games

Hi guys !

I have this question. How to force a user to change orientation
of the phone from portrait to landscape? I have noticed that in other games this kind of drawing appears. How to adapt this to a html game for Defold ?

Usually a platform where you upload your game (poki, yandex.games and so on) does it for you in their iframe wrapper.

But if it’s not a case for you, then you need to create a custom template (engine_template.html) where you add logic that checks if it’s mobile, then compare width and height of the window and if orientation is wrong shows an image over the game.

3 Likes

Yes, I need this for my game.

I’m afraid I don’t know enough about JS.

Maybe someone has an example ready ?

I struggled with the same issue a while ago. Couldn’t find a solution whit js that works in every browser. But found a way to solve it inside Defold.

Use orthographic camera library to find the viewport.
Then in render script check if viewport.z < viewport.w. If it is draw the icon you want, disable the input etc.
Else draw the game.

2 Likes

Thank you very much for your advice. !

I still have this question. Is it possible to have the game turn on in fullscreen mode by default ?

Yes, there’s a fullscreen checkbox in game.project. For Android also check the Immersive Mode checkbox.

1 Like

Sorry, I didn’t write that it was about a game created in HTML. I know that for the mobile platform there is such an option in the project configuration.

Ah, I don’t think it is possible to start in fullscreen mode in a browser. The browser is likely preventing any such attempt unless it is triggered by user interaction (such as a click).

2 Likes

@Sayuris1 Can you provide an example ?