Skip to content

Ability to limit canvas size for Expand scale mode. #7027

Closed

Description

@leha-games

The "Expand" scale mode in Phaser is generally excellent, but it has a significant issue.

When I configure my game with a width of 1080 and a height of 1920 (a portrait mode game), and use the "Expand" scale mode, the canvas size can become excessively large when the screen is in landscape orientation with a wide aspect ratio. For instance, the canvas might expand to 5000x1920 or even larger, depending on the aspect ratio.

I encountered this problem when my game started crashing on all Android devices in landscape mode with a Framebuffer status: Incomplete Attachment error.

The solution seems to be the ability to configure maximum canvas width and height limits (something like maxCanvasWidth and maxCanvasHeight options).

While max.width and max.height config options already exist, they appear to only limit the size of the HTML element, not the actual canvas width and height. I haven't been able to find a suitable way to use these options to prevent the excessive canvas size issue.

Activity

  1. self-assigned this
    on Feb 5, 2025
  2. zekeatchan commented on Feb 5, 2025

    @zekeatchan
    Contributor

    Hi @leha-games, could you provide code examples so we can have a closer look?

    Also did you set the parent property in the game config?

    Without setting the parent property, you will need to manually call the setParentSize method in the Scale Manager to set the maximum width and height for the canvas.

    An example of the parent property in the scale object in the game config should look something like this:

    const config = {
        type: Phaser.AUTO,
        backgroundColor: '#2dab2d',
        scale: {
            mode: Phaser.Scale.EXPAND,
            parent: 'phaser-example',
            width: 800,
            height: 600
        },
        scene: Example
    };
  3. leha-games commented on Feb 5, 2025

    @leha-games
    Author

    There is example from my phone. When I set this config:

    const config = {
        type: Phaser.AUTO,
        backgroundColor: '#2dab2d',
        scale: {
            mode: Phaser.Scale.EXPAND,
            parent: 'phaser-example',
            width: 1080,
            height: 1920
        },
        scene: Example
    };

    Image

    It throws this error:

    Image

    Also it can be achieved on PC:

    Image

  4. photonstorm commented on Mar 4, 2025

    @photonstorm
    Collaborator

    Thank you for submitting this issue. We have merged a PR that fixed this and pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

  5. locked as resolved and limited conversation to collaborators on Sep 1, 2025
  6. photonstorm commented on Oct 13, 2025

    @photonstorm
    Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions