Hi guys,
I have found a bug with the particle system and the multi-atlas texture. If your particles are on the first sheet, the particles work fine. If they are on the second sheet, then they do not render correctly, it looks like the offset is being created incorrectly. In the image, the full coin is correct, the two half coins is from the second texture in the multi-atlas.This is the same if i only render frames from the second atlas. Is this expected behavior?
Cheers
samme
August 23, 2023, 5:13pm
2
I guess it’s a bug, you could add an issue.
Thanks for the reply. I actually just found someone posted the issue and a workaround:
opened 12:39PM - 30 May 23 UTC
🔮 Renderer (WebGL)
<!--
Thank you for taking the time to contribute towards Phaser. Before submitt… ing your issue, check the following:
1. This repo is for Phaser 3 only. Phaser 2.x issues should be raised in the [Phaser CE](https://github.com/photonstorm/phaser-ce) repo.
2. This repo should not be used for technical support. If you're struggling to use Phaser then post your question to the [forum](https://phaser.discourse.group/) or [Discord](https://phaser.io/community/discord) channels. GitHub Issues are for bugs and feature requests only.
3. Make sure your issue isn't a duplicate, or has already been fixed.
4. If your issue contains _any_ form of hostility it will be closed and you will be blocked from access to all our repos. Be nice. We do this for free.
5. If all the above is ok, fill out the template below.
-->
## Version
<!--
Enter the version of Phaser you're using. You can find this output to the Dev Tools console in your browser.
-->
* Phaser Version: 3.60.0
<!--
Place the operating system **below** this comment.
-->
* Operating system: Windows 10
<!--
If the bug is browser specific, please enter the version **below** this comment:
-->
* Browser: Chrome
## Description
<!--
Write a detailed description of the bug **below** this comment. Include the expected behavior and what actually happens. If the issue is device specific, please say so.
-->
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
<!--
All issues must have source code demonstrating the problem. We automatically close issues after 30 days if no code is provided.
The code can be pasted directly below this comment, or you can link to codepen, jsbin, or similar. The code will ideally be runnable instantly. The more work involved in turning your code into a reproducible test case, the longer it will take the fix the issue.
-->
```javascript
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](https://github.com/photonstorm/phaser/assets/16494063/2d4871d2-bd94-4065-942d-0322a0046c27)