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

Wrong glTexture when adding particles using multi-atlas, in 3.60 #6515

Closed
Demeno opened this issue May 30, 2023 · 2 comments
Closed

Wrong glTexture when adding particles using multi-atlas, in 3.60 #6515

Demeno opened this issue May 30, 2023 · 2 comments

Comments

@Demeno
Copy link

Demeno commented May 30, 2023

Version

  • Phaser Version: 3.60.0
  • Operating system: Windows 10
  • Browser: Chrome

Description

As of Phaser 3.60, when adding particles in the new format, using a multi-atlas, sometimes the wrong pixels would be rendered.

I've already found why this happens, here's an explanation:

The pixels are taken from the wrong atlas in the multi-atlas.
The reason this happens is that the sourceIndex of the frame is ignored.
The reason that the sourceIndex in the frame is ignored, is that in the new format the texture is internally set without the frame by calling setTexture(texture) in the ParticleEmitter's constructor.
This causes the emitter's texture to have as its frame the firstFrame, which would always have a sourceIndex 0, instead of the sourceIndex specific to the frame that is defined in the ParticleEmitter's config.

Workaround:

Calling setFrame(frameName) again fixes the issue, see example below.

Example Test Code

class Example extends Phaser.Scene
{
    preload ()
    {
        this.load.path = 'assets/atlas/';
        this.load.multiatlas('megaset', 'tp3-multi-atlas.json');
    }

    create ()
    {
        // Good - This frame from the 1st atlas would be displayed correctly
        this.add.image(40, 60, 'megaset', 'diamond')
        // Good - This frame from the 2nd atlas would be displayed correctly
        this.add.image(80, 60, 'megaset', 'gem')

        // Good - These particles of a frame from the 1st atlas would be displayed correctly
        this.add.particles(40, 200, 'megaset', { frame: 'diamond' });
        // Bad - These particles of a frame from the 2nd atlas would be displayed incorrectly
        this.add.particles(80, 200, 'megaset', { frame: 'gem' });

        // Workaround
        this.add.particles(40, 340, 'megaset', { frame: 'diamond' }).setFrame('diamond');
        this.add.particles(80, 340, 'megaset', { frame: 'gem' }).setFrame('gem');
    }
}

Example output:

image

@photonstorm
Copy link
Collaborator

This issue has been mentioned on Phaser. There might be relevant details there:

https://phaser.discourse.group/t/bug-phaser-3-60-particle-system-and-multi-atlas-texture/13491/3

@photonstorm
Copy link
Collaborator

Thank you for submitting this issue. We have fixed this and the fix has been 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.

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

2 participants