Managing Different Mobile Screen Sizes - Haxe, OpenFL

What is the best way to get closer to the variety of screen ratios of Android mobile phones?

I am currently using EXACT_FIT, which forces (stretches) the application to the target screen. But how can I dynamically resize my content to a display coefficient, so the content remains visually in the same ratio.

+3
source share
4 answers

If you want to dynamically resize and position the elements, you will need to get the actual resolution of the screen, and then calculate the coefficient of resizing based on some value of the "base" resolution.

You can get screen sizes using

lib.current.stageWidth lib.current.stageHeight

, 0 .

+2

WINDOW, :

Lib.application.window.width
Lib.application.window.height

:

Lib.current.stage.width
Lib.current.stage.height
+2

, . , , , . , . , ( ) .

0

I would recommend determining your position and the size of the content as a percentage of the width and height of the screen. In the pseudo-haxe code (I'm learning Haxe / HaxeFlixel right now;)):

class Registry {
    ...
    static var SCREEN_WIDTH;
    static var SCREEN_HEIGHT;
    ...

    static var X_UI_HUD_TITLE = 0.15;
    static var Y_UI_HUD_TITLE = 0.05;
}

...

class HUD {
     var title:FlxText;

     public function new() {
         title = new FlxText();
         title.x = Registry.SCREEN_WIDTH * Registry.X_UI_HUD_TITLE;
         title.y = Registry.SCREEN_HEIGHT * Registry.Y_UI_HUD_TITLE;

     }
}

Thus, SCREEN_WIDTHthey SCREEN_HEIGHTcan change, but the text titlewill be in the same visible position.

0
source

All Articles