1. Download our Official Android App: Forums for Android!

Apps Convert Pixel Units on Different Screen Densities

Discussion in 'Android Development' started by SoulMazer, Feb 10, 2011.

  1. SoulMazer

    SoulMazer Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Nov 5, 2010

    Nov 5, 2010
    4
    0
    5
    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.
     

    Advertisement

  2. SoulMazer

    SoulMazer Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Nov 5, 2010

    Nov 5, 2010
    4
    0
    5
    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.
     

Share This Page

Loading...