I'm writing a 2D game and am having a really hard time getting my head around screen independence, I've read all the official guides, but I still can't work it out so I'm hoping someone here will set me straight once and for all!
I have a sprite which jumps like so:
Y Co-ordinate = Y Co-ordinate - jumpamount (say 15 DIP worked out by 15 * (current screen dpi/160)
jumpamout = jumpamount - step amount (again in DIP, this time I've gone with 1 on an MDPI screen, so 1.5 on HDPI, .75 on an LDPI)
Now, obviously I can't subtract 1.5 from the jumpamount (or .75 for LDPI screens) as I can only work in whole pixels, so how exactly is this supposed to be done? What I'm trying to achieve is that the sprite jumps to the same heigh on each of the screens - when I say the same height, I mean of course, relative to the screen (like say, if, at it's max height it is exactly 1/2 way up the screen on a MDPI screen, then I want it be 1/2 way up the screen at that point on all the different screens).
If I explicitly use 1 for the 'step' amount in the above psuedo-example, then great, it's always a whole number, but it doesn't result in the correct jump height across all screens.
I just can't seem to find anyone who knows the answer - I've been trying to work it out for myself for about 4 months now with no luck so I'm getting a bit frustrated to say the least!!
Would really appreciate it if someone could explain to me exactly how this is supposed to work on Android!
Thanks very much and happy new year!!!!!




