Android game catering for all screen sizes - idea - java

I have been developing a game for Android and I had an idea for catering for the different screen sizes, and I would like feedback on whether the idea is a good one, and how it can be improved, or if it shall be scrapped.
What I have is a 2d size scrolling game, where it is locked it landscape mode. Because screen sizes vary, the width of the screen (usually height, but it is in landscape so I shall refer to it as width) changes. This causes all sorts of problems for me with moving the background because it is basically two identical pictures scrolling, and as one leaves the screen the other begins to replace it, so I must catch the image when it has just left the screen, so it can be reset and ready to scroll again. This means it must reach an int value every time, else it will not be caught and both images would scroll off screen.
My idea, which I have briefly tested is as follows. Truncate the screen size to the nearest 100px. Add 100 to this value and have that as the width for the background images. Then divide this value by 100 and use this as the rate of px per frame it moves. This would mean that the background would move at a similar rate dependent upon screen size (set frame rate of 25FPS). It would move faster on larger screens and slower of smaller screens, but would move at the same speed relative (1% per second or whatever).
Is this idea flawed? I have tested it vaguely on a few screen sizes but the emulator is verry laggy, and I only have a couple of devices to test it on (I am only 18 so I cannot get my hands on many!).
Any feedback appreciated.

Related

Real time screen recording in a LibGDX screen

In short, I'm making a simulation where I have a bunch of creatures that can see each other. The way I want to do this is to capture an area around each creature and give it to their neural network, and make them evolve to recognize their surroundings. I am coding this using LibGDX, and I don't plan on making screenshots every single frame because I can imagine that that is already a very poor idea. However, the problem is that I don't know how to get the pixels inside a defined square without capturing the entire screen and then cherry picking what I want for each creature, which will cause a MASSIVE lag spike, since the area these creatures will be in is 2000x2000, and therefore 12 million different values (4 million RGB values).
Each creature is about 5 pixels (width and height), so my idea is to give them a 16x16 area around them, which is why iterating through the entire frame buffer won't work, it would pointlessly iterate through millions of values before finding the ones I asked for.
I would also need to be able to take pictures outside of the screen (as in, the part outside the window's boundaries), if that is even possible.
How can I achieve this? I'm aiming for performance, but I do not mind distributing the load between multiple frames or even multithreading.
The problem is you can't query pixels in a framebuffer.
You can capture a texture from a framebuffer, and you can convert a texture to a pixmap.
libgdx TextureRegion to Pixmap
You can then getPixel(int x, int y) against the pixmap.
However, maybe going the other way would be better.
Start with a pixmap, work with the pixmap, and for each frame convert the pixmap to a texture and render that texture fullscreen. This also removes the need for the creatures environment to match the screen resolution (although you could still set it up like that).

Purpose of Virtual width/height in libgdx java

I watched a video by a guy I think is very good with game development, ForeignGuyMike and in his tutorials he uses a virtual width and height and scales it by 2. Here is a screen shot of the code.
I am starting a brand new game and want to know if there is some type of purpose to this. I want to know the pros and cons of this because I can't seem to find where he explains why and where on the internet someone does this. He then multiplies the virtual width and height by the scale for the size of his window. Any help is extremely appreciated.
First go through this article by Xoppa, it should clear your basics. But just to understand by an example.
Say you have a screen of width height = 1980x1020px. Now in your game, you hardcode your character size be 100px which looks fine. But if same game is started on a screen of 1280x720px that character of 100px height will be too big.
One way is you use relative values always. For example, take height of screen every time game runs and set your character height be SCREEN_HEIGHT/10. Now you have to follow this everywhere, set character tail height be SCREEN_HEIGHT/11.5 and so on. This could be hard to handle once your game starts to grow.
But if you create a screen camera of say 20x11(virtual screen size) and set character height be 1.2f then no matter what the screen size be, your character size will always be relative to the ratio of height. Because you are working independently from pixels. Everything is explained in the above article by the way.

How to make my 800*600 game fit all screen resolutions?

I have created a game that is 800*600. How can i make it so that it will fit all computer screens? How would this normally be done? Other sites have said too set everything to a certain ratio depending what the screen resolution is. But if each image in the game changes size in comparison to the screen resolution it would mean that the images would not be in the right places and cause other problems. Is it possible to just "Stretch out" my 800*600 game so it fits any size? Thanks
You need to make the game resolution-independent. That means you create your own concept of 'game units' (which might be exactly the same as pixels relative to an 800x600 screen if you want), and then operate exclusively on those game units.
Whenever you draw something to screen you convert co-ordinates and sizes from game units into pixels. You will need to have functions that can convert both ways, because you may also want to translate click-events from screen space to game space.
When you start your game, you need to decide on the screen resolution and aspect ratio. If the aspect ratio is not the same (eg widescreen), you might choose to either stretch the game area or letterbox it. By moving all the translation code to a lower level and operating only within your game units, you save yourself a lot of pain in the long run.
Yes, you can stretch it out. Make the Games' main components on a JPanel that is 800 by 600, and add that JPanel to your JFrame. Then the player can resize your JFrame and the components won't go offscreen, they will change shape and size based on the new size of the JFrame. Remember that the mouse's position in relation to the JFrame will change a bit, but divide the mouses position by the JFrames height/width and multiply it by the JPanel height/width to get the position in relation to the JPanel. With this method you can let the user maximize your game and still have components look normal.

Android: Scale fixed Layout down

i want to scale my android application, basically i developed it for 800x480 display with a AbsoluteLayout. This is necessary for my Application, i can't change it.
Now the Problem:
When i start my app in the Emulator the buttons disappear and the images are extremly large. I thought android would scale applications with a fixed size down by default, but it does not work. I already tried to manipulate the manifest but this did not work.
I use a ImageView component for graphics.
Targeting Android 2.1
Cheers
Felix
It is definitely not ideal to use AbsoluteLayout. But, if you want to just push through with it, you should switch the units of all your co-ordinates and sizes away from px (pixels) to dp (density independent pixels). You will have to scale all of your existing co-ordinates by a factor of 2/3 to start, since 1 dp = 1.5px at the density that your layout targets (hdpi).
You will need to explicitly specify the sizes of all your images and layouts. If, for example, you had a button that was 30px wide and 120px tall, then it will become 20dp wide and 80dp tall.
Of course, the images won't look great on smaller (mdpi) screens, since they will be scaled to 2/3 size. Also, some devices are fixed to landscape mode, where you will definitely encounter layout problems. So it's not pretty, but it may get you over the finish line, depending on your requirements.

Android Supporting Multiple Screens with fixed width icons

This may not be explained the best but here it goes.
I have a window of 2 by 2 square icons. I found a custom layout script that spaces these equally on the screen. These 4 icons consist of a square background with a little image and title.
At the moment the width and height are defined in dp. But that stretches or shrinks the text. I am assuming I need to use fixed values. I understand that there are 4 generalised screen resolutions.
My question is, for small I would have to set the width and heights to x and y, but when the screen gets bigger due to larger devices I would have to increase x and y to keep some sort of continuity.
Is there a minimum and maximum width and height of screens for each size? How do other people get around these issues.
Sorry if it is a bit broad and sweeping, but I am new to creating dynamic (ish) displays for multiple resolutions.
Any help and advice will be greatly appreciated.
Google has actually documented this well. When you load your images in your res folder, you will need to simply put high, medium, and low res versions of your file into the file with the same name (but with hdpi and so forth appended to the name of the file). Android will handle which file to choose based on the screen size. I could go through how to do this, but this link covers the details of what I'm talking about in greater detail. Also, check out this question I answered a while back. It has a lot to do with your question.

Categories

Resources