Assets behaviour in multiplatform libGDX application - java

What is the best practice to store resources in libGDX library. I'm know that I can use AssetManager and also e.g. I can link the resources from android folder into iOS, but I dont know how it will behaviour on multiplatform devices. The resources are scale according to screen size/operating system, or I need to manually set diffrent size or resulution in each platform resource folder.I want to avoid any ovelaying or stretch behaviour.

There are many ways to go about this and there is no "best" solution. However if you do already build for android just use the android assets folder. This is the default and will be used for other builds (due to the default libgdx project configurations).
The resources only scale if you tell them too. You can choose to use a viewport (a fit/fill viewport will not stretch but can add black/background bars that do not have the default aspect ratio). But you can also choose to implement screen dependency yourself by using the aspect ratio and the scale.
For instance:
A 1080x1920 mobile phone vs a 1440x1920 tablet
If you use a fit viewport you will have unused space on the tablet. if you use a fillviewport you might lose stuff on the phone. But if you take the phone as a default aspect ratio and calculate the width offset for the tablet (1440-1080/2) you can use this value to choose to put actors/sprites on the same location as on the prone (by using this offset) or relative to the screen edge (by using the screen size). I personally use this to place the UI relative to the screen and the game itself the same as on the phone. You can even choose to use a different layout depending on the aspect ratio.
Do note that in this way you will also have to calculate a global scale and use this everywhere in your application. This can be tedious to implement but gives you much more control!
So if you have a simple game and you don't care about tablets or different screen sizes I suggest you start with a fit viewport.
p.s. Not sure what you mean by "multiplatform devices", but as I said, the default libGDX setup does the heavy lifting here, so I suggest you use it!

Related

Java Swing app looks tiny on high-DPI screen when it should be scaled to normal size

How can I make my Java Swing app GUI scale properly to users on high-DPI screens?
See the screenshot below. At the top you can see how tiny the app looks compared to Ubuntu's file explorer icons and gedit. In the bottom left you can see roughly what size the app should look like (and does look on regular DPI monitors). So I'm looking for a way to scale the GUI of the app properly when a high DPI monitor is in use. For example, gedit looks the same on both regular DPI and high DPI monitors. I want my app to behave like this.
Here is source code for the app: https://github.com/baobabKoodaa/baopass
This is an extremely common problem affecting many apps. Roughly half of the apps I run on Ubuntu are scaled properly without any actions from the user, the other half are not scaled and look really tiny. Note that I'm mainly looking for a solution that doesn't require actions from the user (although any help is appreciated at this point - I haven't found any ways to scale it at all).
According to this scaling should already work out of the box. It doesn't. I'm not sure if this is a bug or if there is some additional step I'm supposed to do besides running the app on Java 9?
You have to tell the drawing libraries to scale the app up.
GDK_SCALE=2 ./application
Will have the appropriate information set in the environment and the widgets will render scaled up such that each pixel effectively takes four pixels of footprint.
Note that the splash screen (if you use Java's splash screen support) isn't presented after the entire Swing libraries are loaded, so it won't scale regardless of the settings you attempt.
In some platforms, like the Linux distribution of Fedora, partial scaling is also possible, such that you can set GDK_SCALE=1.5. Just keep in mind that it's not universally available, and it is not settable to any scaling ratio you might want.
Finally, the older JVMs ignore this setting completely, so if you aren't launching with Java 9 or higher, odds are it won't work. And, of course, the way that things are tweaked for older JVMs and different operating systems tend to vary (if they work at all).
It looks like you're using Linux. You can use a command line switch
java -Dsun.java2d.uiScale=2 -jar some_application.jar
From https://wiki.archlinux.org/index.php/HiDPI#Java_applications

Android Studio - Drawable folders

I have three general questions regarding android's drawable folders.
Do i put different sized images in each of these folders, or will the images automatically scale themselves? As in, does android decrease the quality of the .bmp files automatically if placed in these folders?
When using the android design preview screen, will the appropriate image from the appropriate drawable folder be shown? If I have to make different sized images for each folder, I want to ensure that what i'm seeing in the design preview matches what is shown on other devices.
Lastly, do the drawable folders, if used, help to avoid the issue with failing to allocate memory for drawables on devices? I have had to scale my images down, and yet my college's phone still cannot allocate enough resources.
I couldn't find answers to these specific questions anywhere, so i'd really appreciate the help with these!
1) You don't need the different folders if you will put the same things in those folders. The designer/developer puts the resources that most adapt to that configuration.
2) You can select what kind of device you're previewing the design with (resolution and dpi), on the design tools. It will attempt to load the appropriate resource for that configuration.
3) Loading smaller images into memory may be helpful, as well as resizing them before displaying them (libraries like Picasso can do this out of the box), or you could be looking at a leak of some sort.
About your first question, you should create four different drawable folders in app>res in order to provide different devices (with different screen sizes and densities) more convenient images.
/drawable-ldpi For low density screens.
/drawable-mdpi For medium density screens.
/drawable-hdpi For high resolution screens.
/drawable-xhdpi For extra high resolution screens.
Android does not decrease the quality of .bmp files when they are allocated in those folders. You have to fill each folder with the correct sized images.
About second question, I am not sure whether the android design preview screen uses the correct images or not, but in a real app running on a phone, it will.
And third question: sorry, but not.
Good luck!
Ad 1 I always find it really helpful to load drawables to my project using Android Drawable Importer plugin. It will take care of loading appropriately-sized image into appropriate drawables folder.
Ad 3 If that works for you, maybe try loading images from server using tools like Glade or Picasso? That way you don't clutter your app with unnecessary resources, making it too heavy data-wise. Use a local drawable as placeholder only, in case there's no internet connection.
I'd also recommend using .png over .bmp format, .png are lossless and compressed, meaning your images can get significantly smaller while not losing quality.
You have to put images in different folders as per the image size. it will not generate automatically.
You can not select image for that screen. you can just select different screen sizes android studio will automatically use proper images for that.
For memory issue you can add this line in manifest :
android:hardwareAccelerated="true"

Image Sizes for Themes

I'm looking at making my own theme in CodenameOne but I cant find out quite what I need to do (I should point out I'm new to codename one)
From what I can see the key to what I need to do revolves around Multi-Images. I place an image there and the designer scales it multiple times so that I have all the images needed for the multitude of devices. Clearly, if it's scaling, the exact size of the image I put in Multi Image is a little irrelevant but what is the optimum size (presumably the close to the largest dimensions that will be used?). Can anyone give me an idea about the resolution of, say, a background image that I'm going to put into Multi Image and the correct (or best) aspect ratio?
Historically we recommended making retina iPhone sized images then importing them using the "Quick Add Multi Image" menu option and picking "Very High" as the target DPI.
This still works rather well but recently there has been an influx of higher DPI devices (iPhone 6+ and newer Android flagships) so we might update that guideline in the near future.

Changing UI in Java Android

I have an application in my android tablet. The user interface of that application is really bad. I want to make another level -if this word is correct- and use the same application. I won't add new operations, functions. I just want to make the buttons, labels and texts look better.
Is it possible to re-design the UI, or make a layer between the user and application?
Thank you very much.
EDIT: I don't have the source code, unfortunately.
Use dip in your xml views instead of px.
To make it look better design it for different screens . Make folders for layouts like
1.layout-small( for phones like samsung galaxy mini)
2.layout-medium(for phones like samsung galaxy note)
3.layout-large(7-10 inch tablets)
4.layout-xlarge(10+ inch devices)
Make sure that file names and views ids should be same to avoid null pointer exceptions in run time . Just play with views attributes and sizes in xml files.
For further details see this
Realistically, It would be tough to changes the UI without sourcecode, as you would not know hows these UI controls will work and look. In simple way you can change the orientation of activities as per need such as portrait to landscape in menifest file, add images for different resolution and adjust padding and all. But this wont be good solution.
check this link, would help you bit Android App for Tablet and Phone
You need to check this out first and foremost:
http://developer.android.com/guide/practices/screens_support.html
Android is designed to be used on multiple devices. It allows you define different layouts (UI's) for devices of different sizes and screen resolutions.
You can use stuff like Fragments as well to divide your apps functionality into smaller pieces and display only those parts which suit the current device.

Android drawable paradigm!

I have been developing Android application since 3 to 4 months. I am naive, But pretty much exposed to all of the fundamentals regarding application development on android. However I found really painful while developing application with lots of images, By saying images I mean one of my application has around 10 to 13 images(Small enough to accommodate screen size). The problem is I have to make different copies of it by making,
HDPI - High resolution support
MDPI - Medium resolution support
LDPI - Low resolution support
I have come up with an idea,
IDEA : My idea is to actually have only MDPI images in drawable folder, When my
application will installed first time, I want my application to detect what type of
resolution is supported by device? After knowing which resolution is supported one of my
built in method will either use a MDPI version(images), if handset supports it or else
it will scale up or scale down my images and stores into internal storage for future
reference. When user uninstall my application I will remove these images from internal
storage.
Now this idea has raised a question,
Question :
Whether this idea is feasible? and Programatically possible?
If it is, Should I be really concerned about one time computational overhead?
Is there any mechanism(third party) which can ease my problem? (I hate photoshop and scaling up and down all those images)
Any expert help or guidance will be a big favour!
Thanks in advance!
Krio
I dont really understand why you would do this. The system already basically does this for you. You dont have to specify different images for different display densities, the system just gives you the opportunity to so you can make your app look its best. If you only supply a single image the system will scale it appropriately for you based on the density of the handset.
As for help with scaling the images yourself for packaging, you could look at image magick. This is a powerful scriptable image manipulation tool. You might need to spend a bit of time getting up to speed with it, but I am sure you could write a script that you could reuse for all of your images after that to convert high dpi images to lower dpi ones by scaling down.
Take a look to this article. It describes how android handle directory names for resources. Also take a look a look to this - how android choose the best match for directory name. If you want to use the same resource for all dpis just place it in the default drawable folder.

Categories