- Home /
Android GUI resize problem
I am trying to make an iOS game work on Android and, of course, I am experiencing problems regarding resolution on android devices.
Is there a reason why this works on Android:
 GUI.Button(new Rect(Screen.width/2 - 94 , Screen.height/2 + 35, 188, 76), "", logoMessage)
But not this (which is the same thing after the maths):
 GUI.Button(new Rect(Screen.width/2 - utilities.GetRelativeWidth(300), Screen.height/2 + utilities.GetRelativeHeigth(100), utilities.GetRelativeWidth(600), utilities.GetRelativeHeigth(240)), "", logoMessage)
What I mean is, whenever I try to make the resolution of everything (my game is all GUI based) dynamic it won't work, but if I put absolute values, then it works... I now this because I've put absolute values to fit my devices's resolution (320x240) but I can't just let it this way or else every other resolution my game is played on won't work anymore...
The relative resizing:
 public class UtilityBag  {
 
  private const int MAX_WIDTH = 1024;
  private const int MAX_HEIGTH = 768;
  
  public int GetRelativeWidth(int original_w)
  {
  return original_w * (Screen.width/MAX_WIDTH);
  }
  
  public int GetRelativeHeigth(int original_h)
  {
  return original_h * (Screen.height/MAX_HEIGTH);
  }
 
 }
Answer by cj_coimbra · Aug 14, 2012 at 11:45 PM
This seems to work... at least for what I need... it will make everything as % of the Screen.width and Screen.height...might look strange on some aspect ratios but I guess I'll have to live with that!
 public class UtiliyBag  {
 
  private const int MAX_WIDTH = 1024;
  private const int MAX_HEIGTH = 768;
  
  public float GetRelativeWidth(int original_w)
  {
  return Screen.width * (((original_w * 100.0f)/MAX_WIDTH)/100.0f);
  }
  
  public float GetRelativeHeigth(int original_h)
  {
  return Screen.height * (((original_h * 100.0f)/MAX_HEIGTH)/100.0f);
  }
 
 }
return (int)((float)original_w * (float)Screen.width / (float)$$anonymous$$AX_WIDTH);
fewer mathematical operations 8)
Your answer
 
 
             Follow this Question
Related Questions
Resolution Multiplier on Android 1 Answer
Resolution for assets on Android 1 Answer
Scaling GUI When Screen Width is Adjusted 1 Answer
How to create a resizable GUI 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                