- Home /
How can i make my game matching all Android Mobile Screen?
Hello , Please i feel disappointed really , i can't get clear solution or script or Tutorial for this problem for 10 days.
I build my game in resolution 1280 x 720 and it's awesome. but if i change it by editor to any aspect ratio, the game is not good.
I did Maincanvas with Scale with screen size , screen space - camera.
i add sprite render for background and i write the script to make background the same canvas.
but i can't make all game to be matching with all resolution aspect ratio.
please tell me clear solution for this question:
How can i make my game matching all Android Mobile Screen?
need a bit more information please... is it a 2d game or 3d ? is this a background sky, horizon or something else? a game-board ? For Ui the easiest way is to set a screen space overlay camera set to stretch to fill to the screen edge, then all your other ui, fits inside here, and clamps to the edges. if you need a 3d background, use a skybox on the camera's clear settings. for 2D, just make the backdrop much bigger than the screen. Never assume a fixed size device screen.... all devices are different. please provide some more info
Answer by MohameDiab · May 09, 2020 at 06:44 AM
it's 2D game , iam using Main Canvas and have a many photos inside it like child. Screen Space overly ! not working because when i change aspect ratio ! the images is look different not not like good like 1280 x 720 !
i am beginner but i think it's very hard i wasted time every day for 10 days and more than 10 hours per day in this issue ! i can't get clear solution please help me !
Answer by JonnyHilly · May 09, 2020 at 09:51 PM
its takes a while to get the hang of the Ui system, its not intuitive but its pretty powerful once you learn it. so here it is in rough.... you'll have to learn about each thing mentioned, or find a demo somewhere that already does it, and copy the structure.....
you already have screen space canvas that is step 1 next build your hierarchy inside that object,... say name it MainParent, and set its rect transform mode to expand to fit... this one will then match the size of your device.... now inside that.... you want a bunch of photos.... maybe you want then in a scroll window ? so make another child object... ad a scroll component. and inside that object... make another child, call it Container.... add a layout component to the container... maybe a gridLayout Component inside the container.... make more objects, each with an "image" component for your photos.... check the checkbox on those images to maintain aspect ratio. setup the scroll component's variable to point to your container.
That much may get you a grid of photos at correct aspect regardless of device.
More tricky stuff....
You may need to use a combination of the following 2 component types to get everything looking perfect.... ContentSizeFitter, and Horizontal, Vertical or Grid LayoutComponent ContentSizeFitter is good to put on a parent, if you want it's size to increase based on the child objects.... ( possibly your scroll rect 'container' object) LayoutComponents control how child objects fit next to each other... say for example you put a grid layout component on your Container. then all the photos would be put into that grid. you can set the size of each grid square in the layout component. ...and the "keep aspect" ratio checkbox will keep your images for being stretched. that should be enough to get you pointed in the right direction.... learn those components and you'll be set.
please help me to edit this code the (transform.localscale) is wrong ! can you tell me how to edit it
public class Screenfit : $$anonymous$$onoBehaviour { public int WorkingXorRatio; public int WorkingYorRatio; public bool ChangeX; public bool ChangeY; public bool ChangeXRotated; public bool ChangeYRotated; public Transform $$anonymous$$ainCamera; private int HeightStore; private int WidthStore; private float ratiox; private float ratioy; private float xdistance; private float ydistance; private float newxdistance;
void Start()
{
HeightStore = Screen.height;
WidthStore = Screen.width;
ratiox = Screen.width * WorkingYorRatio;
ratioy = Screen.height * WorkingXorRatio;
if (ChangeX)
{
transform.localScale.x = transform.localScale.x * ratiox / ratioy;
transform.localScale.x = transform.localScale.x * ratiox / ratioy;
xdistance = this.transform.position.x - $$anonymous$$ainCamera.position.x;
newxdistance = xdistance * (ratiox / ratioy);
this.transform.position.x += newxdistance - xdistance;
}
if (ChangeY)
{
transform.localScale.y = transform.localScale.y * ratioy / ratiox;
xdistance = this.transform.position.y - $$anonymous$$ainCamera.position.y;
newxdistance = xdistance * (ratioy / ratiox);
this.transform.position.y += newxdistance - xdistance;
}
if (ChangeXRotated)
{
transform.localScale.y = transform.localScale.y * ratiox / ratioy;
xdistance = this.transform.position.x - $$anonymous$$ainCamera.position.x;
newxdistance = xdistance * (ratiox / ratioy);
this.transform.position.x += newxdistance - xdistance;
}
if (ChangeYRotated)
{
transform.localScale.x = transform.localScale.x * ratioy / ratiox;
xdistance = this.transform.position.y - $$anonymous$$ainCamera.position.y;
newxdistance = xdistance * (ratioy / ratiox);
this.transform.position.y += newxdistance - xdistance;
}
}
}
Your answer
Follow this Question
Related Questions
Keeping Aspect Ratio without filling screen 0 Answers
Clamping after forcing aspect ratio 0 Answers
Handling Multiple Resolutions in 2D? 0 Answers
Build game in portrait aspect without blue borders? 0 Answers