- Home /
Help with Resolution / Scaling
Hey guys,
I really need some help with resolutions in Unity3d, it's driving me crazy.
Do you know some good and up-to-date tutorials or documents to read? Or even got a template for starting new games or from which to learn?
I am now creating a flappy-bird like game. People with different resolutions must not have advantages, so it must be static, like: 800x1280 and all other should expand or shrink proportional.
So, what I tried: Screen Space - Camera -> Scale with Screen Size x800 y1280 with 0.5 Match (which resolution shall I pick her anyways.., does it even matter?) Then, I needed an UI Text for a score or something. UI Text needs a Canvas. An UI is in the front and all other' elements are very small in comparison to the UI, so I have my objects moved to children of the canvas with a scaling of 200 (so it fits, but its strange... why do I have to scale with 200).
Additionally, I am using transform.localPosition instead of transform.position, it seems that position multiplies it with 20.000 or something, strange x-coords. I added Polygons Collider (which I cannot edit somehow, heard, it is an Unitybug..) and if I change the offset of x by 1, it's almost out of screen, whereas the collider component before with 85 fitted perfectly... wtf?
One last problem is the velocity: On Landscape it is much slower than on Portrait, how to fix it? (I hope it'll be fixed automatically with the answer of my questions above)
I'd be very very grateful, if someone could help me with that (maybe even via skype or something) or could at least explain to me what and why that happens...
Now that's a broad question. First i would just say I think it's a bad idea to parent all of your gameObjects to the ui canvas.
Secondly, you can't change the shape of the device's screen or its native resolution, so you must decide what exactly you mean by "People with different resolutions must not have advantages". If someone has a wider screen, do you want to show exactly the same amount of game world width-wise and cut from top and bottom, show the same amount of game world height-wise but more width-wise or do you want to have black bars aroumd the game view so the aspect ratio doesn't change.
Forget the ui first. Just make the game camera adapt to the screen size the way you want.
Yes there is up to date documentation e.g. about the resolution you mention
What do you mean with the velocity stuff? Are you using physics or your own code for moving things? Are you printing out the velocity and looking at the mumbers or does it just look like it moves faster? (perhaps because the view is more zoomed in in landscape and it travels across screen in less time or because some weirdness caused by using physics for objects in the UI)
1) Oh, I don't have to? I hadn't it for first, but then, I thought I had to if I use a canvas. For example: Backgroundimage - should it be a canvas Image or just been dragged from project? But if I do it without UI, how can I add a Text score with the right resolution?
2) I thought about a fixed width and a proportional height rect centered in the mid, filling the bottom and top with black (or rather colors which fit). I think stopping the aspect ratio to be changed is the easiest way.
3) Which camera do I take then? I think about Ortographic, but do I have to change the size then? And do I have to attach the camera to something or the canvas later to the camera? Sorry for these questions, I read many different ways to do it.
4) Yeah, I am using Unity physics, my character moves not really faster, it's just because there is more width the character can move.
Thank you for your help
//Edit: But when I dont attach the objects to the canvas, I cannot use the "Scale with Screen Size"-function, so I'll only use Anchors?
If it's a 2D game, use Sprites and orthographic camera, not UI components to make the game graphics. CanvasScaler and rectTransforms etc. let you fine tune the UI in very specific ways and align things to the corners of the screen or to other UI objects. I haven't actually tried making a game with just UI components but I'm pretty sure you'll run into some unexpected behavior very easily.
How the orthographic camera works and how to scale ortographicSize to different screen sizes has been the topic of many a question here so you should find info about it pretty easily.
If you want the camera to show exactly X world units height-wise, set the orthographicSize to 2*X
. If you want the camera to show exactly X world units width-wise, set the orthographicSize to (float)Screen.height / Screen.width / 2f * X
I recommend you figure out a way to circumvent static resolution. Otherwise you'll be forced to letterbox your screen or find some other inelegant solution. As a solution to a traditional flappy bird: keep the height fixed. When using a wider screen and you don't want to show what's further ahead (ie: prevent advantage of looking ahead), just show more of what's behind the bird. This allows for the whole screen width to be used without giving players with wider screens an advantage.
Is it really the height which is being fixed at such games? I think it's the width because of advantages, but okay I see, then it becomes static. But how would I do that this way, setting the Character about 200px Left with pivot on the right border of Camera Screen? And align all objects pivots to the right border of Camera Screen? And how can I Destroy them then? At the moment, I am checking for x < 0 - Screen.width. I think I'll limit it to portrait mode. And how would I be able to set up your solution with the Camera, do I even need that Scale with Screen Size? Don't know yet what resolution one uses there.
I am really grateful for your help, thank you.
Hey, could you give me a hint on that?
Still haven't figured out how to scale width without a canvas... Tried it this way:
if (screenWidth != Screen.width)
{
var change = Screen.width / screenWidth;
float test2 = test.GetComponent<SpriteRenderer>().bounds.size.x;
test2 /= change;
test.transform.localScale = new Vector3(change/test2, 1, 1);
screenWidth = Screen.width;
}
but it's acting really strange... is it even the right way to do it by scaling the SpriteRenderer?
Your answer
Follow this Question
Related Questions
Internal collisions 1 Answer
Detecting a UI element is over another UI element 1 Answer
Buttons still "Clickable" after disabling their parent canvas 0 Answers
Scale box collider to camera view? 2 Answers
Allow Click Through some UI Elements 1 Answer