Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resolution independence in Android SurfaceView

I am currently starting a game engine in Android, first foray into the platform and have the basics in place however i am unsure of the best way to approach resolution independence when using SurfaceView to draw graphics.

Looking for pointers as to how to keep the game / sprites etc all looking the same independent of the screen, obviously it wouldn't be efficient to scale all the sprites every frame or store many variations for differing resolutions

like image 810
Tom Avatar asked Jan 16 '10 20:01

Tom


1 Answers

You'd just scale the sprites when you load them. I am guessing you're loading them as Bitmaps from a Resource, right? If that's the case then all you need to do it something like this:

BitmapFactory.Options options = new BitmapFactory.Options();
options.outHeight = spriteHeight * scale;
options.outWidth = spriteWidth * scale;

Bitmap sprite = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.sprite, options)

Where scale is based on the change of the screen size.

like image 122
CaseyB Avatar answered Sep 21 '22 19:09

CaseyB