Get full stage size on Android



  • Hi, I'm currently scaling and rearranging my game's graphics according to the device's resolution but i'm having trouble getting the real resolution of my test phone because Lib.current.stageWidth returns 1196 instead of the actual 1280 that I would need.

    I'm guessing this is because I think Lib.current.stageWidth is probably not counting the top bar or something like that, but I would love to hear if anyone has got any advice or ideas of how I could fetch that actual 1280 number

    Thanks!


  • administrators

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



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

    Space Castle is a free retro style platformer game with a mystery storyline and made using the haxeflixel library.

    0


  • @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. :)

    Space Castle is a free retro style platformer game with a mystery storyline and made using the haxeflixel library.

    0


  • @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


Log in to reply