+4 votes

Is there a way to get dpi/ppi of the display? This e.g. is handy for constant size on-screen controls with mobile devices.

in Engine by (40 points)

2 Answers

+3 votes
Best answer

Haven't tried it out myself but maybe look at OS.get_screen_dpi()

by (50 points)
selected by

Might need to do

OS.get_screen_dpi(OS.get_current_screen())

Just to get the dpi from the screen where your game runs if there should be multiple screens.

–4 votes

There are three options that i see:
1. Ask a user at start or in options what is his screen size in inches and calculate it
2. Publish different versions for different devices
3. Use function: get_model_name() (don't know if this really returns model of device because it's undescripted in help)

by (444 points)

Thanks for the suggestions, but seriously? There is

getWindowManager().getDefaultDisplay().getRealMetrics(metrics)

on Android, not sure about iOS and in Unity it's

Screen.dpi

Pretty sure the typical user is not too keen to figure out and enter device specifications.

Where did you found this? Can't find it in api.

I gave a downvote because i really think these solutions are "thin".

I think its a really bad idea to assume that the user knows the screen size, I would say that it is always best to assume that the user is "stupid".

To publish a version for different devices could be possible in some cases, but even if for example a version is for "mobile" only there are still a ton of screen sizes and resolutions.

I am not sure how get_model_name() works on different devices, only tried it on desktop pc where it just returns "generic device" and therefor tells us absolutely nothing. Even if it returns the exact model it would still require to have a huge list of models and the respective screen size, and when new devices are in sales, we would have to update that list.

If it isn't for some very specific case, design your game to be responsive! One way or another.

Godot even have some build in methods of handling different screen sizes/resolutions

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.