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

Mask or RenderTexture doesn't work until it is resized. #6662

Closed
pavels opened this issue Oct 28, 2023 · 0 comments
Closed

Mask or RenderTexture doesn't work until it is resized. #6662

pavels opened this issue Oct 28, 2023 · 0 comments

Comments

@pavels
Copy link

pavels commented Oct 28, 2023

Version

  • Phaser Version: master / dev
  • Operating system: Linux
  • Browser: Chrome

Description

Mask from render texture and maybe other don't work until it is resized - this is most likely related to #6527 - i am opening new issue as the behavior is different now - but still wrong.

See example code - until you press space, the mask doesn't work - when you press space, it starts working.

Screen resize is there so the it all behaves correctly - it will behave same way if you move resize of the game outside of the event handler or even not resize the game at all, just the scratch effect will be wrong (unmasked part doesn't correspond to where the mouse is)

Example Test Code

https://labs.phaser.io/edit.html?src=src/game%20objects/render%20texture/render%20texture%20as%20a%20mask.js&v=dev

class Example extends Phaser.Scene
{
    preload ()
    {
        this.load.image('brush', 'assets/sprites/brush1.png');
        this.load.image('pic', 'assets/pics/brilliance-jim-sachs.png');
    }

    create ()
    {
        const rt = this.add.renderTexture(400, 300, 400, 300);

        const mask = rt.createBitmapMask();

        const pic = this.add.image(400, 300, 'pic');

        pic.setMask(mask);

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

            if (pointer.isDown)
            {
                rt.draw('brush', pointer.x - 32, pointer.y - 32);
            }

        }, this);

        this.input.keyboard.on('keydown-SPACE', event =>
        {
            this.game.scale.resize(800, 600);
            rt.resize(800, 600);
        });
    }
}

const config = {
    type: Phaser.AUTO,
    parent: 'phaser-example',
    width: 400,
    height: 300,
    scene: Example
};

const game = new Phaser.Game(config);
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant