-
-
Notifications
You must be signed in to change notification settings - Fork 103
Description
Describe the project you are working on
A multi-platform tower defense game with responsive UI and various UI elements that get swapped / reconfigured when window changes occur.
Describe the problem or limitation you are having in your project
Every multi-platform game requires a bunch of boilerplate code to facilitate window and device orientation changes. There are notifications for window position and size changes (NOTIFICATION_WM_POSITION_CHANGED and NOTIFICATION_WM_SIZE_CHANGED) and @bruvzg indicated that a signal for when a window mode change completed is on his todo list. That leaves game devs like myself with one more unnecessary piece of boilerplate implantation that is essential to every mobile game: device orientation.
To facilitate changes to the UI and gameplay that react to device orientation changes, this piece of code currently travels to every project I have:
signal device_orientation_changed
var _is_portrait: bool = false
var _last_orientation_is_portrait: bool = false
func _process(_delta: float) -> void:
var ws: Vector2i = DisplayServer.window_get_size()
_is_portrait = ws.y > ws.x
if _last_orientation_is_portrait != _is_portrait:
device_orientation_changed.emit()
_last_orientation_is_portrait = _is_portrait
Describe the feature / enhancement and how it helps to overcome the problem or limitation
DisplayServer.device_orientation_changed - which emits when a mobile device's sensor puts the game in another orientation (eg. landscape or portrait).
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
I suspect there are already places in the engine that keep track of the state of the windows, so adding a window changed signal to them should be trivial.... but I don't know any C++ so I could be wrong.
If this enhancement will not be used often, can it be worked around with a few lines of script?
See the code example above.
Is there a reason why this should be core and not an add-on in the asset library?
I think it is unnecessary that every professional game developer writes this boilerplate code for themselves and takes it to every project they start. Making the signals part of core means nobody has to worry about their implementation of this code. It's not much code, but hey, every bit of convenience helps.