Phaser API Documentation

  Version: 

Member of: Phaser.Structs.Size

constrain([width], [height], [fit])

Description:

The current width and height are adjusted to fit inside the given dimensions, while keeping the aspect ratio.

If fit is true there may be some space inside the target area which is not covered if its aspect ratio differs. If fit is false the size may extend further out than the target area if the aspect ratios differ.

If this Size component has a parent set, then the width and height passed to this method will be clamped so it cannot exceed that of the parent.

Parameters:

name type arguments Default description
width number <optional> 0

The new width of the Size component.

height number <optional>

The new height of the Size component. If not given, it will use the width value.

fit boolean <optional> true

Perform a fit (true) constraint, or an envelop (false) constraint.

Returns:
Description:

This Size component instance.

Since: 3.16.0
Source: src/structs/Size.js (Line 452)