Search code examples
androidactionscript-3flashairadobe

Adapt game to device resolution with Adobe AIR


I want to put a flash game of mine on Android thanks to Adobe AIR but I don't know how to resize everything depending on the device resolution. Is there a way to do so? I tried with this script I found in an Adobe guide:

function handleResize(...ig):void {
   var deviceSize:Rectangle = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
}
handleResize();

It doesn't work and I haven't actually understood how it should work.


Solution

  • Neh, that ain't gonna work. There is hundreds of ways to adapt your application to different device sizes lemme expose the simplest method i have found, in fact there is an air app of mine that is currently working this way:

    First, you must make sure that all your game is contained in the same display object container OTHER than the stage, for example "Game". Then you simply rescale it using as reference the shortest dimension of the device. Voila:

        public function createGame():void{          
            addChild(scaleAndAlign(new Game()));
        }
    
        public function scaleAndAlign(target:DisplayObject):DisplayObject{
            var scale:Number = 720 / stage.stageWidth;
            target.scaleX = 1 / scale;
            target.scaleY = 1 / scale;
            target.y = (stage.stageHeight - target.height) / 2;
            return target;
        }
    

    Beware! Your game's top and bottom will be cropped in order to make your application fit the entire device's stage. To test this use different device resolutions. Should you have any doubts of the results, check out our Whack a Robot app on the PlayStore and check out the results.

    I.