Advertisement
Guest User

Untitled

a guest
May 5th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 2.08 KB | None | 0 0
  1. //add this event listener somewhere
  2. //"starstage" is the starling stage
  3. //"flashstage" is the flash stage
  4.  
  5. starstage.addEventListener(ResizeEvent.RESIZE, onresize);
  6.  
  7. private static function onresize(e:ResizeEvent) {
  8.     updategraphicsmode(e.width, e.height);
  9. }
  10.  
  11. private static function updategraphicsmode(windowwidth:Int, windowheight:Int) {
  12.         if (!_fullscreen) {
  13.             if (flashstage.displayState == StageDisplayState.FULL_SCREEN_INTERACTIVE ||
  14.                 flashstage.displayState==StageDisplayState.FULL_SCREEN){
  15.                 flashstage.displayState=StageDisplayState.NORMAL;
  16.             }
  17.         }else {
  18.             if (flashstage.displayState == StageDisplayState.NORMAL) {
  19.               try {
  20.                     flashstage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;   
  21.                 }catch (e:Dynamic) {
  22.                     #if flash
  23.                     if (e.name == "SecurityError") {
  24.                         if (flashstage.loaderInfo.url.indexOf("file://") == 0) {
  25.                         }else {
  26.                             Debug.log("Error: Haxegon is unable to toggle fullscreen in browsers due to Adobe security settings. To do: make haxegon_flash addon!");
  27.                         }
  28.                     }
  29.                     #end
  30.                 }
  31.             }
  32.         }
  33.        
  34.         if (windowwidth == 0 && windowheight == 0) {
  35.             //if returning to windowed mode from fullscreen, don't mess with the
  36.             //viewport now; leave it to the onresize event to catch
  37.             return;
  38.         }
  39.        
  40.         starstage.stageWidth = screenwidth;
  41.     starstage.stageHeight = screenheight;
  42.        
  43.         // set rectangle dimensions for viewPort:
  44.         var stretchscalex:Float;
  45.         var stretchscaley:Float;
  46.         var stretchscalex:Float = Std.int(windowwidth) / screenwidth;
  47.         var stretchscaley:Float = Std.int(windowheight) / screenheight;
  48.         var stretchscale:Float = Math.min(stretchscalex, stretchscaley);
  49.        
  50.         var viewPortRectangle:Rectangle = new Rectangle();
  51.         viewPortRectangle.width = screenwidth * stretchscale;
  52.         viewPortRectangle.height = screenheight * stretchscale;
  53.        
  54.         viewPortRectangle.x = Std.int((windowwidth - Std.int(screenwidth * stretchscale)) / 2);
  55.         viewPortRectangle.y = Std.int((windowheight - Std.int(screenheight * stretchscale)) / 2);
  56.         // resize the viewport:
  57.         Starling.current.viewPort = viewPortRectangle;
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement