How would I go about making responsive mobile controls for my game?

Godot Version

Godot 4.4

Question

Hi.
I’m working on a web browser game and I need to make mobile controls that appear only if the game’s being played on a mobile device.
I have no idea on how that could be done honestly.

My only idea would be checking window / screen size somehow but is that even possible in godot?

Edit: Maybe through OS.get_name()

1 Like

Oops sorry,I thought you are taking about responsive ui,and yeah you can’t see the os in web export version! You should check for the screen size!
Here’s a demo:



func _ready():
    var size = OS.get_screen_size()
    var min_side = min(size.x, size.y)

    print("Screen size:", size, " | Shortest side:", min_side)

    if min_side < 1280:
        print("Likely a phone/tablet")
    else:
        print("Likely a desktop/laptop")

You can check different sizes or just ask the player that is it on a desktop or phone!

1 Like

Yes, OS.get_name() in combination with OS.has_feature() would be my best bet

2 Likes

Thanks for the confirmation and for the script, this really makes things easier, I used to make a copy of every project just to add the extra controls, it was a pain lol.

1 Like

I’ll look into it, thank you.

Try both ! Pick which one works best!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.