I am currently working on a 2D game for Android. All of the images that I render were created as SVG's and then exported to PNG's which I have placed in my assets directory. These images are also all sprites that I render using a sprite batcher.
My question is around using different versions of the sprites for devices with different densities. I know that when developing a traditional android app you could place separate directories for separate density levels inside of res and then place the correctly sized versions of the images in question in these sub-directories of res.
What is a good approach when dealing with sprite images in the asset directory? Should I just have one copy of the sprites at a really high density / resolution that I use for everything and I just render them on a coordinate system that is independent of screen size or should I resize the image based on screen density before I process it to create all my texture regions? Or is there another solution entirely?
Currently I have one high resolution set of sprites that I use for everything, it just seems wasteful and inefficient for the lower density devices.
the best answer(s) that I got to this question are on gamedev.stackexchange: https://gamedev.stackexchange.com/questions/69970/recommended-way-to-handle-sprite-assets-for-different-screen-densities-android
Related
Regarding Android's call to provide multiple versions of a bitmap/image, why can't only the highest resolution image be used?
E.g if the xxhdpi image is available - will that be able to scale down to all lower density versions or will it just mean it will scale bigger than the allocated size (View)?
PS: If I'm using a background image, does scaling matter? E.g. should I still provide multiple versions of 1 image to fit different pixel densities?
Usually image scaling operation is resourceful and the outcome might be worse than using pre-scaled image.
It has already been answered several times, but I will answer it again. Btw I'm not myself a big pro in Android, but I will try to answer in the best way possible.
Automatic scaling is a thing in Android, but using that is a waste of resource, we already know that using a PNG Graphic asset is a waste of CPU/GPU power when we can use XML for basic designs (which uses less resources), so why waste more power for downscaling it (which increases app opening time and makes it laggy), simply creating multiple sized images for different display sizes is the best option.
A simple and convenient option is to use a free software like Adobe XD which supports export into different sizes.
Simple answer: Avoid using PNG(or other image format), but when you don't have other options do create multiple sizes to save resources.
For using images in my android application, I will use this technique :
I put all of my images into "drawable-xhdpi" folder to let the application scale the images down for various resolutions.
I wondering does it make sense ? What is your experiences ?
Thanks for sharing...
UPDATE:
Maybe this method is a nice one, But an another question raises here which is :
Does this technique causes a memory leak for ldpi devices? I don't want to solve the problem by using svg images, Suppose there are bit-mapped images which are not vector based and there is no choice or alternative to replace. using a bitmap is the only choice.however using this method has a cons which will affect the overall layout and in some devices the position of relevant controls will be changed.
While this will work, it's not ideal and not recommended. Please look at the official documentation for Supporting Multiple Screens:
Although the system performs scaling and resizing to make your application work on different screens, you should make the effort to optimize your application for different screen sizes and densities. In doing so, you maximize the user experience for all devices and your users believe that your application was actually designed for their devices—rather than simply stretched to fit the screen on their devices.
And:
Provide different bitmap drawables for different screen densities
By default, Android scales your bitmap drawables (.png, .jpg, and .gif files) and Nine-Patch drawables (.9.png files) so that they render at the appropriate physical size on each device. For example, if your application provides bitmap drawables only for the baseline, medium screen density (mdpi), then the system scales them up when on a high-density screen, and scales them down when on a low-density screen. This scaling can cause artifacts in the bitmaps. To ensure your bitmaps look their best, you should include alternative versions at different resolutions for different screen densities.
You can use the File / New / Image Asset to automatically generate the scaled assets.
Best way is use SVG files instead of PNG and import them to project in Androis studio: File -> New -> Vector Asset or use icon fonts like https://github.com/mikepenz/Android-Iconics
SVG file is inserted to drawable and converted to PNG files while compile time for back compatibility, but you don't need to maintain a pack of files, but just one vector file.
I use inkscape to create svg drawings and also to convert to png I think the conversion has better quality and supports all svg functions.
With inkscape and a script it is possible to do batch conversion, I have not tried it yet, until now I convert them one by one
Very much a newbie question here but I cannot find a clear answer on the net or in the books I have. I am designing an app to be compatible with all sizes of android devices and I want to display a images in my app. I understand that android automatically scales images to suit the resolution of the screen being displayed.
My question is what do I look for in the images I use? E.g. I have a picture that's 2418 x 2192 # 240dpi. As far as I can tell, this should be perfect for a larger screen such as a tablet. If I put this into the xhdpi image folder in my project will it be detected by other devices and scaled to suit their dimensions/resolutions? Do I have to create 3 different versions of this image in photoshop and put it into the relevant dpi folders?
I can't find a nice beginners tutorial for this stuff so haven't a clue what I'm doing!
This is the best place to start for multiple screen size support:
http://developer.android.com/guide/practices/screens_support.html
The short answer is, yes, you place the images in the different directories based on resolution and Android will select which image to use based on the device's properties. You should make a smaller set of images, for example, for mdpi and hdpi. You don't "have to" do that, and if you just place the image into drawable it can be scaled down, but that's generally not the best way to go.
This is something you'll deal with on just about all project, because there simply are so many Android devices. This resource has helped me greatly.
If you have a resource in only ONE folder, Android will scale it for you. The different drawable folders are intended to allow the developer to provide properly scaled images with minimal effort. For example, you'll want to provide an xhdpi in addition to the "standard" mdpi image to make assets look better on high-resolution devices. The app would work fine (and have scaled images) in all resolutions, even if you provided only a single image. However, if you provided a xhdpi drawable, then there's a bit of overhead to scale all of those down, and especially for icons, the results may not look very good (or even be recognizable).
I generally provide assets for mdpi and xhdpi, but if the app will see frequent use on low-res devices, I provide the ldpi as well. If possible, I include all four.
Note: The image you mention is much too large to be included in the UI resources and would probably best be placed in assets and loaded on request. Even on xhdpi devices, it would have to be scaled down.
I've recently started testing for my game on other peoples phones. For some reason the whole game is getting really "blurry" for their phones, but not for mine. All of them has got a higher android version then I do.
I've tried finding a good answer around the web for this, but all I can find is the answer for if you are using the res/drawable folders. I am loading my images from the assets folder with a special load method. I am then stretching them out when I draw them onto the screen with the "c.drawBitmap()". I am drawing using an "android.view.View".
So now, anyone that has the answer for turning the anti-aliasing off for bitmaps when creating 8-bit games. It would be an impossibility for me to resize the images before rendering them onto the screen, because of me creating an image from an integer array, that refreshes with a rate of about 60 fps.
That blurriness, is most probably because of low resolution of your bitmaps. It may be fine on the test device of yours, but when you use them on higher resolution screens you will either get raw/pixelated or blurry/AA'd results after scaling. An appropriate solution is to have different images for different resolutions, or to be more accurate; densities. Android already do the choosing part:
ldpi
mdpi
hdpi
...
I am assuming you know these identifiers.
Put your high resolution image to res/drawable-hdpi, low resolution to res/drawable-ldpi etc.
I was wondering if there is a way for using one set of images for all the resolutions. I have an application, and I want to port it on all the android resolutions but I don't want to store 3 sets of images, for every resolution category. What would be the best practice to use as less images as possible.
Thank you!
Sure, you can provide only one set of images, in the base drawable directory, and Android will automatically resize as required.
This may result in aliasing and images that are not as clear as would be possible if you were to provide images sized properly.
You probably mean density, not resolution (in Android, applications do not work directly with resolution).
Actually, you don't need to support all 3 densities. Quote from developer.android.com:
This pre-scaling mechanism works independently of the source. For instance, an application targeted for a high-density screen may have bitmaps only in the res/drawable-hdpi/ directory. If one of the bitmaps is a 240x240 icon and is loaded on a medium-density screen, the resulting bitmap will measure 160x160.
I've done simple test: removed ldpi and mdpi density images, launched my app on mdpi skin and it scaled hdpi images nicely. It's not the best practice, but android's prescaling does its part as described.
Please read this for more details.
I wrote a tool which makes this all a lot easier to manage. Although the images are stored in separate directories - the tool shows all resolutions together, and lets you auto-scale from one to another.
you can get it here: http://hobbyistsoftware.com/AndroidImageViewer