• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Android Rotate display runtime

Flaick

Member
Hi all, i've search on help but i didn't find anything. Is possible to rotate the display (landscape to portrait and viceversa) at runtime?
 

2Dcube

Member
If you want to adjust to how the player's holding the device, you can do the below.
In a Step event, check if the display ratio changes. For example,
Code:
if orientation == "horizontal"
{
  if display_get_width() < display_get_height()
  {
    orientation = "vertical";
    // change to vertical UI here or in GUI event
  }
}
else
{
  if display_get_width() > display_get_height()
  {
    orientation = "horizontal";
    // change to horizontal UI here or in GUI event
  }
}
I used this in my app Kanji Quest. You can see it on the different screenshots:
https://play.google.com/store/apps/details?id=com.venbrux.kanjiquest
 

Flaick

Member
But i need to rotate by myself via code, not to catch if user had rotate the phone.

My problem is that i need to play the game in landscape on certain moment, but for some rooms i need to force portrait (and not to change it).
 

trg601

Member
I don't know of a way to set the orientation, but you can use os_lock_orientation() to lock it to the current orientation and then tell the player they have to rotate.
What you could do, though it would require a little more setup, would be to lock the orientation to one (landscape/portrait) in global game settings and then rotate the view and GUI for the parts of the game that you want to force portrait.
 

Mookal

Member
I've actually had lots of experience with this, and it was a total pain to get working but so obvious once I figured it out.
So all you need to do is change both the window size (window_set_size(w, h); ) and the size of the application surface ( surface_resize(application_surface, w, h); ) once you've detected an orientation change. If you've got cameras/views, resize them too, and scale any GUI you're drawing.
Depending on what else you've got going on, there's way more to it, but these are the basics.

BUT! It seems like you could want to actually rotate the entire game window, stuff inside it and all. If that's the case, you can still do what I mentioned above to change the window size, but you'll need to seriously overhaul your GUI drawing methods. I'm pretty sure to rotate the game view, you can draw the application surface, just turned. Or you can change the camera's angle. Whole lotta options here.
 
Top