Use Pixels to set positions and size in Android? - java

I know people asked how to support different sizes but they only cared about the dimensions of the images. My question is somehow different. I want to know if using pixels is a good way to scale everything and also to position images on the screen.
Is there a better way?
I am creating a 2D game BTW.
Regards,
Baracat

Another way that you can do is to having many sets of images at many resolutions as possible then load it dynamically depends on the screen resolution. I am using this method for menus in my 2D games.
EDIT:
For positioning please have a look at this thread

Related

Android - Set Canvas to always be 1920x1080p?

Im developing a mobile game in Java on a canvas. But when I use different sized phones, the alignments are wrong and the hard coded offset values to correctly place buildings don't match with the new canvas proportions. Also, the UI elements are wrong size now and dont match the screenheight. Feeling kind of lost on how to best solve this issue.
I know that hard-coding the game to always be 1080x1920p will probably lead to black bars on some phones, something I'd also want to avoid if possible.
Canvas.scale did not do the trick, it only achieved crashes.
Anybody got experience in this? Thanks!

Using multiple backgrounds in Android Application

Here is a scenario on which i done a lot of research on google but hopeless. the scenario is, i am going to develop a 2D game in which i want to use multiple backgrounds and i want to translate them as they are moving forward, it must look like one background is near and translating/moving fast and the other background is a bit far and translating/moving a little slow. the nearer background have almost full intensity and the farer background have a bit low intensity. you can say they have different transparency levels. the question is, how can i get this task done or is this possible to use multiple backgrounds.
any suggestion will be appreciated.
as an example, see the image of BADLAND game bellow.
I think as far as I got your question you want to put two or more images one over another. I mean if you are trying to overlap the multiple backgrounds and asking for it yes it can be done easily.
What you need to do is to use the FrameLayout. as
"FrameLayout represents a simple layout for the user interface of
Android applications. It is usually used for displaying single Views
at a specific area on the screen or overlapping its child views."
and then you can implements the animations on them and translate them You can find different types of translation over them.
Here is all about using the frame layout frameLayout1 framelayout2 and for animations and translation here are links. link , link2 , link3

How do I expand a Libgdx image from 2 rectangles

I am working on a game using LibGDX, and right now, I am working on the menu screen. What I want to do, is have a small image, set a bounding box, and expand however large I need it. What I think would be optimal, would be to set 2 rectangles. One for width and one for height. If it needs to get bigger or smaller, it would take that rectangle, and duplicate it beside, or beneath the current one, depending if it is for the width or height. I believe there is a builtin class for this, but I cannot seem to find it.
You might want to take a look at NinePatch if I'm not misunderstanding your question. Link here: https://github.com/libgdx/libgdx/wiki/Ninepatches

java android - fit items on a image background with different screen size

This is my first post and i have (i think) a uncommon request...
I'm programming on the last Eclipse Mac, for every android SDK, and i'm using more XML for layout than runtime... So i search a solution in XML if possible.
Here is the situation: i work with an image background wich simulate item like buttons, image, text... etc. On this image, i put buttons, image, and text (buttonview textview etc...) and place it precisely on their places on the image. This solution is very powerful to have good design BUT, if i change the resolution of the screen, and/or its size, each item won't be at its place, and will be translated (horiz and/or vertic) for some "dp"... (and yes i use dp, not mm or px or whatever)
I'm really embarrased because i think thanks to "dp" it keep proportionnality but.. not !
My question is how can i fix my items at their places on the image background, for different screen size/resolution !!
Thanks in advance everyone,
My Best From Lyon,France
First realise that if you want to make it pixel perfect for all screen sizes your out of luck.
Second accept that you can't make it perfect for all screen sizes.
Third you can get far with creating different layout for different screen sizes. You can read a lot about supporting multiple screen sizes here. One important thing to take from here is that you can make layout for the different screen sizes or different density sizes.

Tiled Editor map to optimization

I am using AndEngine to create a project game for school.
I am creating a Tiled map using Tiled. The problem i am having is that i cant figure out the size of the map it should be to fit all devices.
or is there a way to create the Tiled map to fit all screen sizes? If so please let me know.
As of now the TiledMap is to small on tablet devices and on cell phones it is to large.
Any suggestions or tutorials on this?
This is what i want to create. Not exactly like this but it is an example.
There's no built-in function for changing the tilemap resolution in Tiled.
Someone wrote a script to change the resolution of a Tiled map. This might help in making the Tilemap with two sets of graphics.
Generally speaking you should aim to support the two or three primary display resolutions. You may have to optimize the tilemaps for each resolution. An alternative would be to either display borders (assume a larger screen is as big as a slightly smaller one) or scale up the tilemap layer (that will most likely result in visual degradation). That means for the best quality you'll need to create one set of tilemap with the corresponding graphic assets for each of the device resolutions you want to support. There's nothing "automagic" about this.

Categories