Uses the device's screen density (sometimes called the DPI or PPI) to calculate the ideal scale value for the application. The dimensions will be calculated so that the application fills the entire stage, regardless of the screen resolution of the device (or the size of the window, where appropriate). With this in mind, it's best to use fluid layouts, to account for differences in screen resolution and aspect ratios.

On desktop and web, the contents scale factor of the stage is detected to determine the application scale.

On mobile, the appropriate scale is calculated based on the value of Capabilities.screenDPI. The calculation is inspired by native apps on Google's Android operating system where "density-independent pixels" are used for layout.

The following chart shows how different screen densities map to different scale values returned by ScreenDensityScaleManager.

AndroidiOSDensityScale
ldpi1200.75
mdpinon-Retina (@1x)1601
hdpi2401.5
xhdpiRetina (@2x)3202
xxhdpiRetina HD (@3x)4803
xxxhdpi6404

The density values in the table above are approximate. The screen density of an iPhone 5 is 326, so it uses the scale factor from the xhdpi/Retina bucket because 326 is closer to 320 than it is to 480.

The following example creates a ScreenDensityScaleManager:

var manager = new ScreenDensityScaleManager();
application.scaleManager = manager;

The next example creates a ScreenDensityScaleManager with a custom ScreenDensityScaleCalculator with a limited set of densities.

var calculator = new ScreenDensityScaleCalculator();
calculator.addScaleForDensity(160, 1);
calculator.addScaleForDensity(240, 1.5);
calculator.addScaleForDensity(320, 2);
calculator.addScaleForDensity(480, 3);
var manager = new ScreenDensityScaleManager(calculator);
application.scaleManager = manager;
Available since

1.0.0

.

See also:

Constructor

new(?scaler:ScreenDensityScaleCalculator)

Creates a new ScreenDensityScaleManager object.

Available since

1.0.0

.

Variables

scaler:ScreenDensityScaleCalculator

The scale manager's scale calculator.

Available since

1.0.0

.

Methods