• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Convert Pixel Units on Different Screen Densities

SoulMazer

Lurker
Nov 5, 2010
4
0
Hi, I'm currently in the process of writing a 2D game for Android. I have written my own level creator in order to create/edit levels, and I had a question about different screen densities/resolutions.

The only physical phone I have to test is a Droid Incredible, which has a resolution of 800x480 (hdpi). Obviously, I would like my game to be playable on other devices with different resolutions by the time it is completed. I have already created many levels that assume the screen resolution is 800x480, so when I export levels from my editor, each image appears at whatever pixel it was placed at in the level editor.

This is all fine and dandy for when I test the game on my Incredible, but, as I expected, it does not when I try it on emulators that vary in resolution/density. So, my question is this: I know that "dp" units exist and that they can be used to achieve density independence (Supporting Multiple Screens | Android Developers), but I'm not quite sure how to actually use them. If I have a very intricate level designed at the 800x480 resolution, how would I use these "dp" units to basically "scale" the entire level to look the same on any screen?

Or are there any other ways any of you would suggest?

Thanks so much in advance.
 
Well I've been mucking around with this just about all day and have it set up pretty well. I tried converting all of my absolute coordinates to DPI, and it helped, but it did not provide the perfect solution I was looking for. In the end, I got the percentages of each (x, y) point in relation to the total screen width/height. I found by using the hdpi and mdpi folders with scaled images along with percentage-based coordinates, my system is pretty reliable.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones