Working with different display sized

Monkey Targets Forums/Android/Working with different display sized

Raz(Posted 2011) [#1]
To quote the android docs ( http://developer.android.com/guide/practices/screens_support.html )

"Do not use hard-coded pixel values in your application code"

So am I understanding this right? When it comes to drawing, I should be drawing things at a relative position and scale based on the device width and height?

Let's say in development I use the resolution 800x480. At this resolution the scale is 1,1. This means if I draw something at 400,240 I actually draw it at 400,240 at a 1,1 scale.
However if someones phone is 400x240 in res (just an example). The scale would be 0.5,0.5. This means if I draw something at 400,240 I actually draw it at 200,120 at a 0.5,0.5 scale.

This seems to work well, until I have to start considering different aspect ratios.

This all seems very complicated to me, am I missing something and/or making it sound worse than it is?

Thanks
-Chris


Bladko(Posted 2011) [#2]
why cannot You scale Your graphics to fit screen ?? it would be stretched in some cases

SCREENX_RATIO = DEVICE_WIDTH/SCREEN_WIDTH
SCREENY_RATIO = DEVICE_HEIGHT/SCREEN_HEIGHT	
PushMatrix() 
Scale(SCREENX_RATIO, SCREENY_RATIO)
'DO DRAWING
PopMatrix()


in my case for retro low res graphics it looks good on every device from low to high res, but image filtering (or what ever this option is called) should be turn off for this case in mojo.android.java (i am only scalling up)

if you want to use this, you only draw everything to fit yours screenX, screenY


Raz(Posted 2011) [#3]
Oh wow, I didn't realise it was as simple as Pushmatrix, Scale, PopMatrix

thanks :D