Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
leha-games opened this issue Feb 3, 2025 · 2 comments
Open

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

leha-games opened this issue Feb 3, 2025 · 2 comments

Comments

@leha-games
Copy link

leha-games commented Feb 3, 2025

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.

@zekeatchan
Copy link
Collaborator

zekeatchan commented Feb 5, 2025

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
};

@leha-games
Copy link
Author

leha-games commented Feb 5, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants