How to change screen orientation in Godot with code?

  • Thread starter Thread starter Darkmisc
  • Start date Start date
  • Tags Tags
    godot
Click For Summary
SUMMARY

The discussion focuses on changing screen orientation in Godot using GDScript. The user attempted to set the screen orientation to landscape using both OS.set_screen_orientation(OS.SCREEN_ORIENTATION_LANDSCAPE) and OS.screen_orientation = OS.SCREEN_ORIENTATION_LANDSCAPE, but neither method successfully changed the orientation from portrait to landscape. The issue indicates a possible misunderstanding of when to call these functions or the need for additional code to handle orientation changes effectively.

PREREQUISITES
  • Familiarity with Godot Engine 3.x GDScript syntax
  • Understanding of project settings in Godot, specifically screen orientation
  • Basic knowledge of Godot's OS class and its methods
  • Experience with handling user input and game state transitions in Godot
NEXT STEPS
  • Research how to properly implement screen orientation changes in Godot using the _ready() function
  • Explore Godot's documentation on the OS class and its methods for screen orientation
  • Learn about handling orientation changes during runtime in Godot
  • Investigate community solutions or plugins that manage screen orientation in Godot games
USEFUL FOR

Game developers using Godot Engine, particularly those creating multi-orientation games and needing to manage screen transitions effectively.

Darkmisc
Messages
222
Reaction score
31
TL;DR
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.

[CODE lang="python" title="change to landscape"]func _ready():
OS.set_screen_orientation(OS.SCREEN_ORIENTATION_LANDSCAPE)[/CODE]

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:
[CODE lang="python" title="landscape2"]OS.screen_orientation = OS.SCREEN_ORIENTATION_LANDSCAPE[/CODE]

This doesn't work either.
 
Last edited:
We have many threads on AI, which are mostly AI/LLM, e.g,. ChatGPT, Claude, etc. It is important to draw a distinction between AI/LLM and AI/ML/DL, where ML - Machine Learning and DL = Deep Learning. AI is a broad technology; the AI/ML/DL is being developed to handle large data sets, and even seemingly disparate datasets to rapidly evaluated the data and determine the quantitative relationships in order to understand what those relationships (about the variaboles) mean. At the Harvard &...

Similar threads

Replies
1
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
1
Views
2K
Replies
5
Views
2K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K