itch.io icon indicating copy to clipboard operation
itch.io copied to clipboard

Add "Unlocked" Orientation option for Mobile-friendly Web Games

Open rameshvarun opened this issue 2 years ago • 2 comments

I have a browser game that is mobile-friendly - it's designed to be played in both landscape and portrait modes.

Currently, I'm forced to lock it to one orientation or the other. I would instead like the user to be able to pick by simply rotating their device. Would it be possible to add an "Unlocked" option that disables orientation locking entirely? I did try "Default' but that seems to just lock the game to landscape.

Screenshot 2023-04-19 at 1 59 47 PM

rameshvarun avatar Apr 19 '23 21:04 rameshvarun

I see this is a year+ old issue but I'd like to +1 this feature request. Grateful that itch handles putting mobile apps into fullscreen mode on mobile phones but it would be good to additionally have an unlocked orientation for apps that want to offer players the choice of orientation (this is what I thought default would do to be honest). I can fight the itch container by putting in a screen.orientation.unlock() every frame but I'd prefer not to have to do that.

spillz avatar Aug 26 '24 16:08 spillz

It's hacky, but just as the other commenter mentioned, I do this now, and it works:

<script>
  function try_unlock_orientation() {
    if(screen.orientation && screen.orientation.unlock) {
      try {
        screen.orientation.unlock();
      } catch(e) {
        console.warn('Failed to unlock orientation:',e);
      }
    }
  }

  // Let mobile/tablet users decide the orientation.
  // NOTE: Fixes itch.io bug.
  if(screen.orientation && screen.orientation.unlock) {
    try_unlock_orientation();

    // For older browsers.
    window.addEventListener('orientationchange',() => { try_unlock_orientation(); });
    // For modern browsers.
    screen.orientation.addEventListener('change',() => { try_unlock_orientation(); });
  }
</script>

esotericpig avatar Mar 27 '25 22:03 esotericpig