Skip to content

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

@Demeno

Description

@Demeno

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions