Get full stage size on Android



  • I just use FlxG.scaleMode = new FillScaleMode();. works with all screen resolutions.



  • @Gama11 said in Get full stage size on Android:

    Does immersive mode work? That usually enables with a slight delay, maybe stageWidth is 1196 on startup but 1280 slightly later?

    I'm sorry but idk how to set that up? Not super familiar with mobile dev

    @galoyo said in Get full stage size on Android:

    I just use FlxG.scaleMode = new FillScaleMode();. works with all screen resolutions.

    Won't this deform the stage to fill all the space?

    I would live to avoid that at all costs

    Thanks for the replies!



  • @zkylon for me it is better than writing code for all the different screen resolutions. that's my opinion. :)



  • @galoyo it's a pain but it's manageable

    you just align everything to corners so instead of placing say your pause button on pixel (1820, 980) you just place it on (width-100, height-100). that way it works on all resolutions without that much work



  • I'm also having this problem and it's driving me crazy. I want the game to always use the same vertical resolution, then use the ratio of the screen to determine the horizontal resolution (in landscape mode). Then the game should be zoomed in/out to fit the full screen. Since the initial resolution from flash.Lib.current.stage.stageWidth is a little less than what it should be because of the Android navigation bar that auto-hides, the game has a thin black bar on the left and right sides of the screen. I then try to resize the game to full screen shortly after it starts (since the ratio will be correct then), but I've not been able to do this without breaking something.

    The closest I've come to solving this is by first calling "FlxG.scaleMode = new StageSizeScaleMode();" shortly after the game starts, but then FlxG.width and FlxG.height will be wrong (with the screen resolution I think), so I hacked a way to change just FlxG.width and FlxG.height to the values of FlxG.camera.width and FlxG.camera.height (which for some reason are correct). FlxG.resizeGame() would not work like I wanted, the game would not be zoomed to fit the screen.

    This seemed to work, but has an issue. If I quit the game via Android navigation bar, and open it again (so the game resumes), FlxG.width and FlxG.height will have the screen resolution dimensions, so the positioning of elements will be incorrect (since I use FlxG.width and FlxG.height to position things).



  • I made a custom scale mode that I'm using for mobile games. It has a fixed height and the width changes depending on the proportions of the screen. On bigger screens, it shows more of the level but I didn't find problems with it. Here is the code:

    class CustomScaleMode extends BaseScaleMode
    {
    	var ratioX:Float;
    	var ratioY:Float;
    	/**
    	 */
    	public function new()
    	{
    		super();
    	}
    	
    	override public function onMeasure(Width:Int, Height:Int):Void
    	{
    		//landscape
    		if(Width > Height)
    		{
    			FlxG.width = Math.ceil( FlxG.initialHeight * Width / Height);
    			FlxG.height =  FlxG.initialHeight;
    		}
    		trace("width " + Width);
    		updateGameSize(Width, Height);
    		updateDeviceSize(Width, Height);
    		updateScaleOffset();
    		updateGamePosition();
    	}
    	
    	
    	override private function updateGameSize(Width:Int, Height:Int):Void 
    	{
    		gameSize.x = Width;
    		gameSize.y = Height;
    		
    		if (FlxG.camera != null)
    		{
    			var oldWidth:Float = FlxG.camera.width;
    			var oldHeight:Float = FlxG.camera.height;
    			
    			FlxG.camera.setSize(FlxG.width, FlxG.height);
    			FlxG.camera.scroll.x += 0.5 * (oldWidth - FlxG.width);
    			FlxG.camera.scroll.y += 0.5 * (oldHeight - FlxG.height);
    		}
    	}
    }
    


  • @Agustín-Pérez-Fernández that's really cool, not sure if it'll work with my current game cos it uses camera zooms and scrolls in a bit of a weird way but i might use it for another project

    thanks



  • If its just the physical screen size in pixels that you are looking for, then you can also use this:

    openfl.system.Capabilities.screenResolutionX;
    openfl.system.Capabilities.screenResolutionY;
    

    Touch devices in general are always fullscreen. So these will give exact sizes. On desktops they give the current full-screen resolution. If you really only want the size of the stage, then the only width/height pair that seem to work on all scale modes and give the physical width/height of the stage are:

    FlxG.stage.stageWidth;
    FlxG.stage.stageHeight;


  • @Username yeah, I've been using these two sets with generally good results, but the navigation bar seems to be messing things up sort of randomly. Haven't been able to reproduce it yet at least



  • During development, sometimes i make mistakes myself by making a realignment callback when the game resizes. I usually build op an queue (List<>) of objects that needs to be realigned when that happens. Sometimes the order of execution is not correct and produces unwanted results. For example, usually my character is the most important object and needs to be realigned first, the other objects realign to the character. So if the objects get called before the character gets called, the objects will not update the the new cords. I solve these things by forcing the most important object to align first - usually the character. Perhaps you are dealing with a similar logic flaws?

    Also I've found out that on Android the first alignment calls that have any good results, start on the second update() call. Everything prior to that can give unexpected results. This might have todo with adjusting screen orientation., but if i call my alignment prior to the second frame, then android will not align properly. Perhaps related to your problems?

    Also Agustín Pérez Fernández idea/suggestion of making a custom scalemode or alternatively a custom camera is in general a really a good idea for your games. Try and build your games from the ground up with pleasing scale modes or cameras.

    This might not be an answer, but maybe it inspires you. Otherwise please make some example code so we perhaps can take a look?


Log in to reply
 

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.