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, 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.


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.

1 Like