- Home /
Handling different resolutions?
Hi guys, so I just made a simple top-down shooter to get used to unity. I found the co ordinates where the camera ends, and spawned monsters from there, and had a life bar on the top left..etc
Now when I play it on android suddenly I see a whole mess because the view is not the same from pc resolution to the phone resolution (duh).
So is there a way that I can reference directly the camera co-ordinates and instantiate according to where the edges of the camera are? I assume this is how one would handle different screen resolutions...
Thanks, Luke
Welcome to the world of Android development: one platform, millions of different device configurations :)
Generally speaking, it's not resolution that presents the problem: a game running on a 320x240 screen and one running on a 640x480 screen should show the same extents - Unity does that for you automatically. But the problem is when aspect ratio changes: what do you show on a screen that is, say, 640x600? What to do with the 120 pixels or extra "height"?
There's no universal way to handle different screen sizes: scaling, letterboxing, zoo$$anonymous$$g are all options. In your question, you want to know the worldspace coordinates of the four corners of the visible camera viewport - is that right?
Yes pretty much. I guess now it zooms in when it finds a different aspect ratio, which is not desirable as some stuff is left out of the screen. Apparently it seems harder than I thought so I'm gonna have to do some research about this..thanks :)
So now the weirdest thing is happening to me. I used width and height to and then converted it using ScreenToWorldPoint. For some reason when I instantiate moving objects it works fine, but still objects do not show on the screen, even though they are instantiated in the object hierarchy. Then if I log the position generated by ScreenToWorldPoint, and instantiate them on that position they show. Has this ever happened before?
Thanks
Are you doing anything with scale anywhere, if anything that relates to the placing procedure is not at a scale of (1,1,1) you can get odd behavior...?
well I change the scale in a lot of the objects, I didn't know that's bad..although now I changed the object I'm trying to instantiate to 1,1,1 and it's still not showing.
Answer by CasvanMarcel · Dec 19, 2014 at 11:54 PM
I posted a response here to solve this horrible problem http://gamedev.stackexchange.com/questions/79546/how-do-you-handle-aspect-ratio-differences-with-unity-2d/89973#89973
Answer by MrSoad · Oct 29, 2014 at 07:03 PM
You can do something like this :
private var fScreen_Width : float;
private var fScreen_Height : float;
fScreen_Width = Screen.width;
fScreen_Height = Screen.height;
which will give you your current screen dimensions. You can then use this info to adjust whatever you need to.
Edit: You can than do what tanoshimi says and calculate the ratio from these values and use that as your base for adjustments.
Thanks, I'll try to figure out how to work with these :)
Your answer
Follow this Question
Related Questions
Scaling Orthographic Camera Up 2 Answers
2D Game. Screen, Camera and coordinates. 0 Answers
4:3 aspect ratio 0 Answers
Orthographic cameras and screen resolutions 1 Answer
Make camera have a fixed screen size 1 Answer