Size Object Min and Max Constraints

Demonstrates how to use the Size structure to manage dimensions while enforcing minimum and maximum width and height limits.

Size Object Min and Max Constraints, running
800 × 600
GitHub
class Example extends Phaser.Scene
{
    create ()
    {
        const debug = this.add.graphics();
        const text = this.add.text(10, 540, '', { fill: '#00ff00' });

        const child = new Phaser.Structs.Size(420, 340);

        child.setMin(320, 240).setMax(640, 480);

        const draw = () =>
        {
            debug.clear().translateCanvas(10, 10);
            debug.fillStyle(0x00ff00, 0.5).fillRect(1, 1, child.width, child.height);

            text.setText([
                `width: ${child.width}`,
                `height: ${child.height}`,
                `aspect ratio: ${child.aspectRatio}`
            ]);
        };

        this.input.on('pointermove', pointer =>
        {

            child.setSize(pointer.x, pointer.y);

            draw();

        });

        draw();
    }
}

const config = {
    scale: { mode: Phaser.Scale.FIT },
    type: Phaser.AUTO,
    parent: 'game-container',
    width: 800,
    height: 600,
    scene: Example
};

const game = new Phaser.Game(config);

More in Size9 examples