1

I've been writing a 2D Surfaceview game for what seems an eternity now and I simply cannot get my head around screen independence for Android.

Basically, my sprite jumps like so: Y value is decreased by an amount (I call it the 'step amount'), then the step amount is reduced by say, 1 and that goes on until the step amount is a negative number which then in effect gets added to the sprite's Y value and it 'falls' back down - works perfectly (This is the way I've always made sprites 'jump').

The problem comes when I run this on a different DPI screen - it still works, but the sprite jumps to a completely different height relative to the screen size.

I understand why this is happening, but I just can't work out a way to fix it!

How do I get it 'jumping' to the correct height on all screen res? (I'm working mainly with 160 and 240 DPI at the moment)

Thanks, would really appreciate any comments.

Regards

Paul Butt
  • 11
  • 2
  • Just make your initial step amount and decrement interval a function of your screen DPI instead of using fixed values for both? – aroth Jan 04 '12 at 00:55
  • Thanks Aroth, I'm creating my step amount by using 1 * (dpi/160) is this what you mean? On a 240 DPI screen I think it works out at 1.5 - I'm not sure how to work with 1/2 pixels in cases like this - any other help would be appreciated - thanks. – Paul Butt Jan 04 '12 at 01:35

0 Answers0