Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //add this event listener somewhere
- //"starstage" is the starling stage
- //"flashstage" is the flash stage
- starstage.addEventListener(ResizeEvent.RESIZE, onresize);
- private static function onresize(e:ResizeEvent) {
- updategraphicsmode(e.width, e.height);
- }
- private static function updategraphicsmode(windowwidth:Int, windowheight:Int) {
- if (!_fullscreen) {
- if (flashstage.displayState == StageDisplayState.FULL_SCREEN_INTERACTIVE ||
- flashstage.displayState==StageDisplayState.FULL_SCREEN){
- flashstage.displayState=StageDisplayState.NORMAL;
- }
- }else {
- if (flashstage.displayState == StageDisplayState.NORMAL) {
- try {
- flashstage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
- }catch (e:Dynamic) {
- #if flash
- if (e.name == "SecurityError") {
- if (flashstage.loaderInfo.url.indexOf("file://") == 0) {
- }else {
- Debug.log("Error: Haxegon is unable to toggle fullscreen in browsers due to Adobe security settings. To do: make haxegon_flash addon!");
- }
- }
- #end
- }
- }
- }
- if (windowwidth == 0 && windowheight == 0) {
- //if returning to windowed mode from fullscreen, don't mess with the
- //viewport now; leave it to the onresize event to catch
- return;
- }
- starstage.stageWidth = screenwidth;
- starstage.stageHeight = screenheight;
- // set rectangle dimensions for viewPort:
- var stretchscalex:Float;
- var stretchscaley:Float;
- var stretchscalex:Float = Std.int(windowwidth) / screenwidth;
- var stretchscaley:Float = Std.int(windowheight) / screenheight;
- var stretchscale:Float = Math.min(stretchscalex, stretchscaley);
- var viewPortRectangle:Rectangle = new Rectangle();
- viewPortRectangle.width = screenwidth * stretchscale;
- viewPortRectangle.height = screenheight * stretchscale;
- viewPortRectangle.x = Std.int((windowwidth - Std.int(screenwidth * stretchscale)) / 2);
- viewPortRectangle.y = Std.int((windowheight - Std.int(screenheight * stretchscale)) / 2);
- // resize the viewport:
- Starling.current.viewPort = viewPortRectangle;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement