How do I estimate physical screen size?

0 favourites
  • 14 posts
From the Asset Store
A versatile and wide-ranging selection of large to medium-sized creature sounds.
  • I am making a mobile game and want to detect roughly if the screen (window) size is closer to a phone or a tablet. Basically, if it's bigger or smaller than 8".

    I'm reading the documentation for PlatformInfo, but can't make sense of it.

    I found an old post where Ashley says it's possible to estimate screen size from CanvasCss Width and Height. But I tested on my phone and PC screen with the same resolution, and by changing display scaling settings, I get vastly different results.

    • 6" mobile screen set to smallest scale: CssHeight=510, DevicePixelRatio=2.1
    • 15.4" PC screen set to highest scale: CssHeight=618, DevicePixelRatio=1.75

    So obviously this method doesn't work.

    ChatGPT says I need one more piece of information: the PPI (pixels per inch) or DPI (dots per inch) of the screen. Without it it won't be possible to estimate the physical size.

  • Hi I apply these conditions at startup. And after that, I do the scaling and positioning.

    For Android (tablet 1280*800 = 1.6, Fone HD 1280*720 = 1.77)

    + System: PlatformInfo.CanvasCssWidth÷PlatformInfo.CanvasCssHeight ≤ 1.77

    For iOS (iPhone5.5 9/16= 0.56, iPhone6.5 9/19.5= 0.46, iPad 3/4 or 7/10= 0.75 or 0.7)

    + System: PlatformInfo.CanvasDeviceHeight÷PlatformInfo.CanvasDeviceWidth < 0.5

    + System: PlatformInfo.CanvasDeviceHeight÷PlatformInfo.CanvasDeviceWidth ≥ 0.7

    --For Android and for iPhone I did it at different times, that's why I use different initial parameters.

  • igortyhon I think you misunderstood my question. I'm not asking about the aspect ratio. There are thousands of different screens with different aspect ratios, so this metric can't be used to estimate the physical size of the screen.

    In my above example, the aspect ratio for both screens is 16:9, but 15" screen is about 600% larger than 6" screen.

  • igortyhon I think you misunderstood my question. I'm not asking about the aspect ratio. There are thousands of different screens with different aspect ratios, so this metric can't be used to estimate the physical size of the screen.

    In my above example, the aspect ratio for both screens is 16:9, but 15" screen is about 600% larger than 6" screen.

    But the aspect ratio is what really matters for display on mobile devices.

    For example Android. I researched the most massive displays of my android players and made 3 groups for myself.

    --HD group.

    If you have HD ratio, what do you care if it's 1920*1080 or 1280*720 or 854*480. And you do not care how many pixels per inch, the device itself will scale, the main thing that the ratio is observed and nothing is lost from the view.

    --Group with long screen.

    --The tablet group

    It's very convenient to check it all in Google Chrome. You can create the most popular device resolutions. That's enough for me to check for Android and iOS.

    I have read and tried to apply what the developers wrote in the article two years ago, but it all breaks down in practice and turns into manure. Aspect ratio is the only thing that has never failed.

  • But the aspect ratio is what really matters for display on mobile devices.

    I agree, but my question was NOT about the aspect ratio.

    I need to know the physical dimensions of the screen to scale the UI accordingly. Basically, if the game runs on a 6" mobile screen, all texts and buttons will be bigger. On a 10" tablet I can make them smaller. On a 24" desktop monitor I can make them even smaller and fit more information on the screen.

  • There's no way to identify the real physical screen size, at least from information browsers give you. How do you know if the display is a colossal display used by the stage at a concert, or a desktop monitor? There may be no difference in the resolution or device pixel ratio in either case.

    On mobile devices, your best bet is probably just to rely on the screen size reported by Platform Info. That is in CSS pixels so does not vary with the device pixel ratio, and so you can probably work on the assumption CSS pixels are about the same physical size across devices, and so the screen size is a rough indication of the display size.

  • On mobile devices, your best bet is probably just to rely on the screen size reported by Platform Info. That is in CSS pixels so does not vary with the device pixel ratio,

    Unfortunately, when I change scaling/text size in my phone settings, this changes the screen size in CSS pixels reported by PlatformInfo, as well as the device pixel ratio.

    Same phone, different settings:

    CanvasCssHeight=510, pixel ratio=2.1

    CanvasCssHeight=320, pixel ratio=3.37

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Isn't that correct though? If you scale up the display to make everything larger, it in effect gives you a smaller screen size for the same size content, and so content should adapt accordingly. If you could ignore that effect, then you could make an app that keeps everything the same size ignoring the system display scale, which then defeats the purpose of changing the system display scale.

  • Most games ignore the system scaling setting and don't resize their content. Besides, in a mobile game I need to make sure that touch controls are always usable. I can't just scale things down without knowing the physical screen size. The same button may be fine on a tablet, but will be too small for mobile phone screen - impossible to control without a pen.

    I guess the safest solution is to add an in-game setting for UI scale and allow users to change it.

  • May not be relevant or already known but. EDIT: oh wait it's not relevant, post is about trying to detect if using phone or tablet based on any values we could use.

    I tend to use "set canvas size" to platforinfo.innerwidth and such. This sorta emulates the old "crop" mode.

    I use it this way as I want full control over UI position and sizing, like resizing a 1080p window to fullscreen on a 1440p monitor, it keeps everything the same size, nothing scales, so feels more like a software app when you resize the window rather than automatic scaling, and allows me to set positions or use anchor behaviour very easily.

    The only biggest downside for now is 9patch objects, you can scale everything manually, even tiledbg, except for 9patch objects.

    I wish to support normal displays, ultra wide displays, vertical displays, and felt this was most ideal. Perhaps I could use a mix of one of the scaling options and set canvas size to take advantage of the automatic scaling.

  • After some digging I found this site that gives a 1 inch square, at least on my phone.

    https://www.hyperspaces.co.uk/device/

    The code can’t be used without permission it seems but looking at the code shows how it was done.

    Looks like it works by roughly having a list of all devices and their physical screen sizes, and using the values provided by the browser to figure out what device is being used. However in many cases it mostly has to guess.

    It’s probably as laborious to do as it sounds, and will only be good for the devices it knows about.

    Other than that it’s as Ashley says, it’s not possible to get the physical screen size from the browser with JavaScript. Everything I’ve found either says it’s not possible or is wrong.

    The only other idea is if you’re doing an android or iOS export they may be able to access stuff like that. But it just depends on what is exposed to the sdk.

    A setting for the touch controls scale seems like the easiest solution.

  • https://www.hyperspaces.co.uk/device/

    I tried that on my PC display and got out a ruler to check, and it claims to be 25.4mm, but measures more like 33mm. So it's not very accurate!

    Anything which involves "maintain a database of all known devices in existence" is probably not a very good solution anyway...

  • Getting the dpi of a(ny) given mobile device reliably isn't currently a thing that exists.

    A user calibration/one time set up may be your best option. Think rhythm games that rely on user input to calibrate audio and visual latency based on the user's device.

    There are sometimes ways to hide it too, like asking the user to "press 'x' to start" when determining which type of controller button mapping tooltips to display, Xbox vs ps.

  • Most games ignore the system scaling setting and don't resize their content. Besides, in a mobile game I need to make sure that touch controls are always usable. I can't just scale things down without knowing the physical screen size. The same button may be fine on a tablet, but will be too small for mobile phone screen - impossible to control without a pen.

    I agree, have the same problem and is quite frustating.

    I have been trying for years to fix this issue without any luck, as any workaround that I tried was unpredictable in how it would behave on each device, so I always went back to a default setup without making any adjustments.

    Therefore I have to decide:

    1-Make the buttons look good size on PC but it will break on phones as they look so tinny and hard to touch and drag.

    2-Make the buttons look good size on Mobile but they will look huge on PC, like you can see and feel that the size is disproportional and not making sense.

    I tried to adjust per device but it's quite insane.

    A lot of work for something that sounds like it should have an easy solution by now since the gaming industry is huge and generates the most money.

    Not sure if this could work but wouldn't be a solution to add to the layers and extra ScaleRate which will affect only how the layer scales according to device resolution.

    100% = Is normal and it will scale as it does now

    50% = anything on that layer will only scale 50% according to the resolution

    This way we will have more control on how we want some parts of the game to scale up, like UI etc...

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)