Jump to content

Convert dpi to pixels in HTML5 games


 Share

Recommended Posts

Guys, do you know how to accurately convert dpi to pixels on mobile using java script. I am trying to display Admob banner ads in my HTML5 game which is compiled to Android app using cordova and I am trying to leave some space on the game screen for ads. Though I can leave some approximate space but I am wondering if there is some api available (or even a plugin in cordova) which gives accurate conversion from dpi to pixels. Admob ad sizes are defined in dpi and not in pixels.

Link to comment
Share on other sites

15 hours ago, mattstyles said:

dpi isn't a measure of size, so I'm not really sure what you need to do, but, getting the device's pixel density in a browser environment can be done using `window.devicePixelRatio` in all modern browsers.

Does that help?

Not exactly. Since Google specifies ad sizes in dpi, it is already calculating ad sizes for display. I was wondering if there was a quick and accurate way of getting this information in a cordova app. It does not look like a trivial problem though.

Link to comment
Share on other sites

Matt is correct, DPI is a measure of resolution, not a measure of length or width. An ad may have a DPI of 72 but doesn't tell you anything about its size. Try Googling "calculate size of admob ads". Some of the search results look promising.

Link to comment
Share on other sites

16 hours ago, BobF said:

Matt is correct, DPI is a measure of resolution, not a measure of length or width. An ad may have a DPI of 72 but doesn't tell you anything about its size. Try Googling "calculate size of admob ads". Some of the search results look promising.

I know. Already googled and planned to continue it once I am done with my latest game which I plan to convert to Android app. Your response is much appreciated. I just thought it would be easy to pick someone's brain here. At the same time I am also wondering how many HTML5 devs are actually releasing their games to Android, iOS stores.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...