How to change screen orientation in Godot with code?

  • Thread starter Darkmisc
  • Start date
  • Tags
    godot
  • #1
Darkmisc
203
27
TL;DR Summary
I need to change the screen orientation using code, but it's not working.
Hi everyone

My app has two mini-games. One uses portrait orientation (which I've set in project settings). The other uses landscape. I need to use code to switch from portrait to landscape. This is what I've tried.

change to landscape:
func _ready():
    OS.set_screen_orientation(OS.SCREEN_ORIENTATION_LANDSCAPE)

When I click on the button to run the landscape game, the orientation stays in portrait.

Does anyone know the right way to do this?

Thanks

EDIT:
I've also tried:
landscape2:
OS.screen_orientation = OS.SCREEN_ORIENTATION_LANDSCAPE

This doesn't work either.
 
Last edited:

1. How do I change the screen orientation in Godot using code?

To change the screen orientation in Godot using code, you can use the set_screen_orientation() function. This function takes in a constant value, such as SCREEN_PORTRAIT or SCREEN_LANDSCAPE, to set the desired screen orientation.

2. Can I change the screen orientation dynamically during runtime?

Yes, you can change the screen orientation dynamically during runtime by using the set_screen_orientation() function and passing in the desired orientation as a parameter. This allows for a more flexible and interactive experience for the user.

3. How do I lock the screen orientation in Godot with code?

To lock the screen orientation in Godot with code, you can use the set_screen_orientation_lock() function. This function takes in a constant value, such as SCREEN_PORTRAIT or SCREEN_LANDSCAPE, to specify the desired locked orientation.

4. Is it possible to change the screen orientation on specific platforms only?

Yes, it is possible to change the screen orientation on specific platforms only. You can use the OS.get_name() function to check the name of the current platform and then use conditional statements to change the screen orientation based on the platform.

5. How do I revert the screen orientation back to the default in Godot with code?

To revert the screen orientation back to the default in Godot with code, you can use the set_screen_orientation() function again and pass in the default orientation value. This will reset the screen orientation to the default for that specific platform.

Similar threads

  • Programming and Computer Science
Replies
1
Views
456
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
1
Views
380
  • Programming and Computer Science
Replies
4
Views
232
  • Programming and Computer Science
Replies
1
Views
425
  • Programming and Computer Science
Replies
1
Views
733
  • Programming and Computer Science
Replies
5
Views
868
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
4
Views
811
Back
Top