how to make my game run on different devices with various resolutions? - andengine

I'm developing a game for 480*800 resolution screen,but now I want to run it on all other screens I tried to run on 7" screen but my background image and even sprite position are out of order.Can anyone please suggest me with some examples about how to make my game compatible with different screen resolutions.
I used the below code but that was of no use.I have seen somewhere that by using FillResolutionPolicy() along with the below code andengine sets automatically for different screens but I did not notice any change ,so please help me in solving it.
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics)
CAMERA_WIDTH = metrics.widthPixels()
CAMERA_HEIGHT = metrics.heightPixels()

FillResolutionPolicy automatically scales everything depending on your screensize.
Camera camera = new Camera(0, 0, 480, 880);
EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED, new FillResolutionPolicy(), this.camera);
This is what I use, and if I start the game on a bigger device, everything is scaled automatically.
FillResolutionPolicy is probably exactly what you need.
(The code above might not be 100% accurate as I canĀ“t access my actual code right now)

FillResolutionPolicy() is just for the black stripe you have either left/right or top/bottom depending on the screens aspect-ratio. see this post in the andengine forum to read about resolution policy.
the camera width/height has nothing to do with the devices real resolution, since it's projected to either the devices height or the devices width (depending on the aspect ratio of your camera settings & the aspect ratio of the device). there is only one point where the DisplayMetrics are useful - get the screens density/max resolution to load res-depending sprites (like: like higher density, load larger sprites) but that's not your problem atm.
the games i tested andengine with, are all resolution independent and can be run on 4, 7 or 10 inch displays with different resolutions without any addition/code changes.
i think it's more like a coding mistake where you added sprites and background image to the scene. for example, by recalculating CAMERA_WIDTH/_HEIGHT with metrics and sprite positions that depend on the CAMERA_WIDTH/_HEIGHT, you mix up the sprite positions with the devices resolution and everything looks a bit out of order. perhaps you add some code, and i can edit my answer pointing you in the right direction.

Related

Unity can't adjust the camera right for phone app. Any thoughts?

So I created a new project in which I've set my display to be 1440 x 2960. I made a background in PSD with the exact same size, and when I place it in the scene, it appears to be way bigger than the actual camera, which should obviously be the same size. Why is that? I'm quite a newbie and I find this very counter-intuitive.
I think you are mixing up resolution with camera size/field of view.These are Different things things.
And also how big your object is in your scene also depends on : pixels per unit" that uyou set up in your Graphic asset.

UI is shown too small in final (built) game

I'm a newbie to Unity and am learning. I've made my first game which is a simple platformer, along with a main menu. The game also has some text GUI elements. When I run it in Unity's built-in player, the GUI looks fine, but when I build the project and run the game using the .exe, the UI is scaled down.
I'm attaching some screenshots below to clarify this.
(As seen in Unity player)
(As seen in game)
Also, the game UI also looks scaled down:
(As seen in player)
(As seen in game)
I want the in-game UI to be exactly like the one seen in the Unity player.
How do I fix this?
The Canvas can be set to scale with different settings if you want it to be accurate you should choose:
-Scale With Screen Size
Using the Scale With Screen Size mode, positions and sizes can be specified according to the pixels of a specified reference resolution. If the current screen resolution is larger than the reference resolution, the Canvas will keep having only the resolution of the reference resolution, but will scale up in order to fit the screen. If the current screen resolution is smaller than the reference resolution, the Canvas will similarly be scaled down to fit.
1- Go to your Canvas and select the Scale With Screen Size option
2- After that, make sure that the Reference Resolution is the same as the Game Window resolution in your Unity layout, I leave here an example:
As you can see, the resolution set on my Game window is (1024x768) and the reference resolution of the Canvas too.

How to make responsible camera for multiplie resolutions?

I m working and some 2d game for mobile phones relate to chess, and I have a trouble with show board for different resolutions of mobile screens.
Here u can see how it must be on 9:16 resolution:
https://drive.google.com/open?id=1MFt-FtEtqkk7QWQC2oAtMBA0WAgOIV4h
And how it looks on smaller screen:
https://drive.google.com/open?id=11WLYZwHEa9ijXbekzUbE5ZbjbEnjZ6Lb
How can I protect my chess board from cropping?
Answer: it depends on how you want it to look.
If you just want it to fit perfectly horizontally, you need to perform 3 steps:
Evaluate the width of the Sprite (with Sprite.bounds)
Evaluate the width of the current screen (with Screen.width and using the main Camera)
Scale the Sprite to fit the screen
If you are using UI elements, you can do the same thing but you won't need to use Camera, just scaling according to the Screen width (look for RectTransform.deltaSize to give you the size of a UI element).
If you are using UI, also consider using layout groups, they help you with fitting the content to screen size.
Anyway, in a device with small width, maybe the table will get too small and you might have to think about better options to display the board instead of just scaling with screen width.

Resolution issue when building the game

I am using the ViewportHandler script for Unity(https://github.com/dfsp-spirit/way2close/blob/master/Way2Close/Assets/Scripts/ViewportHandler.cs), to allow for my UI to appear the same in different resolutions. I am pretty sure that it was looking just fine and pretty much the same in all resolutions(with different quality graphics due to stretching, but that is fine).
I have opened up my project after a while and I am now noticing that while the game scene looks fine inside the editor, the UI elements change position for all resolutions when building the game.
I am attaching two screenshots to show the difference. The Editor one is the proper one where elements are aligned properly. The other one is when I am building the game and running it full screen.
The weird thing is that when building the game, every resolution displays the wrong way (as in picture 1). So the elements are actually resizing properly, but they are just in the wrong place for some reason and I really can't see why. Any ideas ?
(My Canvas is Screen Space - Overlay, Scale with Screen Size, Ref resolution is 2560/1440, Match width and height and ref pixels 100).
You don't need 3rd party scripts to achieve a constant size on different resolutions. Use the Canvas Scaler component on your canvas and set it to 'Constant Physical Size'. Unity should handle all the rest.
If images/sprites change position, try to change the anchor point to fit your needs.

Gamekit multiplayer and different screen sizes

I am very new to gamekit, so I am starting with a basic game. 2 players on the screen and allow them to just move around at this point.
I am testing the game with an ipad and a phone, so I am quickly realizing the ipad user has a lot more real estate instead of the same space being resized.
How do I setup the level to be the same amount of space on any device, but just magnified accordingly?
Try this for all the nodes that you want to be resized use the .setScale() method:
let scale = frame.width/667
node.setScale(scale)
667 is the approximate width of an iPhone 6. Feel free to play around with the number 667 to get the right magnification.
Basically what this does is it scales the node according to the size of the screen.
Note: Scaling may decrease resolution of any sprites used.