Phaser API Documentation


Member of: Phaser.Structs.Size

fitTo([width], [height])


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

There may be some space inside the target area which is not covered if its aspect ratio differs.

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.


name type arguments description
width number <optional>

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.


This Size component instance.

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