#How can I notified about the device orientation?
5 messages · Page 1 of 1 (latest)
I was able to solve it with this code, I wanted to get the portrait and landscape resolution in the case of mobile and pc.
thanks @tropic nacelle @graceful wadi
# resolution_detector.gd
#
extends Node
func _ready():
get_viewport().size_changed.connect(_on_size_changed)
# The autoload Signals contains "signal viewport_change_orientation(orientation)"
Signals.viewport_change_orientation.connect(_on_viewport_change_orientation)
func _on_size_changed():
var size := DisplayServer.window_get_size()
var orientation := DisplayServer.screen_get_orientation()
# Landscape
if size.x > size.y:
match orientation:
DisplayServer.ScreenOrientation.SCREEN_LANDSCAPE, DisplayServer.ScreenOrientation.SCREEN_REVERSE_LANDSCAPE, DisplayServer.ScreenOrientation.SCREEN_SENSOR_LANDSCAPE:
Signals.emit_signal("viewport_change_orientation", orientation)
return
Signals.emit_signal("viewport_change_orientation", DisplayServer.ScreenOrientation.SCREEN_LANDSCAPE)
# Portrait
if size.x < size.y:
match orientation:
DisplayServer.ScreenOrientation.SCREEN_PORTRAIT, DisplayServer.ScreenOrientation.SCREEN_REVERSE_PORTRAIT, DisplayServer.ScreenOrientation.SCREEN_SENSOR_PORTRAIT:
Signals.emit_signal("viewport_change_orientation", orientation)
return
Signals.emit_signal("viewport_change_orientation", DisplayServer.ScreenOrientation.SCREEN_PORTRAIT)
func _on_viewport_change_orientation(orientation):
print(orientation)
Since the problem is solved can you please close this post?
how? :S
Right click on post -> Close post