GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2020-08-30 17:37:57

gkri
Member
Registered: 2020-08-30
Posts: 3

Get the diagonal screen size in inches

This simple script returns the diagonal screen size of the device the game is running on, in inches. I wrote and use it as an easy way to detect if the mobile device the game is running on is a tablet.

Expand/// get_diagonal_screen_size()
//
//	Returns the diagonal screen size in inches
//
/// GMLscripts.com/license
function get_diagonal_screen_size(){

return sqrt(sqr(display_get_width()) + sqr(display_get_height())) / display_get_dpi_x();
}

Last edited by gkri (2020-08-31 04:59:32)

Offline

#2 2020-08-31 17:24:33

gnysek
Member
Registered: 2011-12-29
Posts: 36

Re: Get the diagonal screen size in inches

This returns size of first screen attached to current device in fact, as to get current screen you need to use combination of window_get_visible_rects + window_get_x/y to find on which screen game runs (except fullscreen - it's always on screen 1 from what I remember).

Offline

#3 2020-09-01 03:23:54

gkri
Member
Registered: 2020-08-30
Posts: 3

Re: Get the diagonal screen size in inches

Thank you for your feedback. Does it make sense to detect multiple monitors if the device is mobile?

Offline

#4 2020-09-01 05:12:48

gnysek
Member
Registered: 2011-12-29
Posts: 36

Re: Get the diagonal screen size in inches

Of course not. I was rather thinking about covering all possibilities, but then script will be much bigger.

Offline

#5 2020-09-01 05:53:55

gkri
Member
Registered: 2020-08-30
Posts: 3

Re: Get the diagonal screen size in inches

Thanks again. Even from this brief conversation I learnt something new!
I would like to attempt to write a more advanced variation for multiple screens, but I only have one screen and I will not be able to test it...

Offline

Board footer

Powered by FluxBB