- Home /
Is there a way to scale everything in my game (GUI, text size, etc.) on Android in Javascript?
Is there a way for me to scale everything to fit the entire screen or do I have to do it manually? That way on some of the newer phones, everything doesn't appear to be very small. Is it possible to do it through the resolution?
Answer by TonyLi · Aug 12, 2013 at 02:09 PM
Manually. For your graphical elements, define your areas in a resolution-independent way -- for example, half the screen width x one quarter the screen height. The guys at Schell Games did a good presentation on this: http://video.unity3d.com/video/3708530/unite-11-scaleable-game. The GUI part is about halfway through the video. They defined a wrapper for Rect that they used to specify proportional dimensions. They also included minimum pixel sizes to make sure elements didn't get too small.
For text size, if you're using Unity GUI and dynamic TTF/OTF fonts, you'll want to choose a font size appropriate for the screen resolution by setting GUIStyle.fontSize. If you have no other heuristic, one brute force way is to figure out your desired text height. Then call GUIStyle.CalcSize repeatedly with different font sizes until you get the size you want.
I also just came across this script: http://forum.unity3d.com/threads/195498-Fully-Responsive-User-Interface-with-Unity-GUI
I haven't used it, but it claims to take care of this.
Answer by dylan92 · Sep 12, 2013 at 06:21 PM
You don't have to do this manually. You can create your GUI once and have it scale to any resolution or aspect ratio with the right tools. Take a look at GUI Essentials. It has what you are looking for, works on mobile and is written in JavaScript.
Your answer
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Android touch gui help!!! 2 Answers
Scripting Meshes Subdivision(Javascript) 0 Answers
What's wrong with my scale script? 2 Answers