Advertisement
PsyOps

RatioFix

Jun 21st, 2014
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1.     public void adjustStagePos()
  2.     {
  3.         int sW = (int)stageBG.getWidth();
  4.         int sH = (int)stageBG.getHeight();
  5.        
  6.         // Device res is not compatible
  7.         if ( w < sW || h < sH){
  8.            
  9.         }
  10.         else{
  11.            
  12.             int ratioW = (int)Math.floor(sW/w);
  13.             int ratioH = (int)Math.floor(sH/h);
  14.            
  15.             if ( ratioW == ratioH || ratioW < ratioH){
  16.                 StageRatio = (float)sW/(float)w;
  17.                 StagePos[2] = w;
  18.                 StagePos[3] = (int)Math.floor((float)h*StageRatio);
  19.                 StagePos[0] = 0;
  20.                 StagePos[1] = (h - StagePos[3])/2;
  21.                 coordOffset = new int[]{ 0, (h - StagePos[3])/2 };
  22.             }
  23.         }
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement