Tom Tom - 7 months ago 52
Android Question

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


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.