Hi, everyone! Looks like i found a bug.
I’ve tried to create kind of smoke effect by standart ParticleEmitter and discovered some unexpected behaviour.
The use case is
smoketrail = new ParticleEmitter("SmokeTrail", Type.Triangle, 1 * COUNT_FACTOR);
smoketrail.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, (float) (1.0f / COUNT_FACTOR_F)));
smoketrail.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
smoketrail.setStartSize(.2f);
smoketrail.setEndSize(1f);
smoketrail.setSelectRandomImage(false);
smoketrail.setParticlesPerSec(0);
smoketrail.setLowLife(10.0f);
smoketrail.setHighLife(10.0f);
smoketrail.setImagesX(3);
smoketrail.setImagesY(4);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
mat.setTexture("Texture", assetManager.loadTexture("Textures/explosions/smoke-skull.png"));
smoketrail.setMaterial(mat);
explosionEffect.attachChild(smoketrail);
Pretty standart. Texture is
As u can see we have 3x4 simple animated texture. But when i run this i see animation in weird order
0-1-2-0-1-2-3-4-5-6…
The primery quiestion is WHY? Is it a bug or it is just me missed something?
The secondary quiestion is why if i change
smoketrail.setImagesY(4);
on
smoketrail.setImagesY(2);
i have right animation order? Ofc texture is stitched by 2, but order is fine:
0:3-1:4-2:5-6:9-7:10-8:11
The effect texture can be one image, or contain a sprite animation – a series of slightly different pictures in equally spaced rows and columns. If you choose the sprite animation:
Specify the number of rows and columns using setImagesX(2) and setImagesY().
Specify whether you want to play the sprite series in order (animation), or at random (explosion, flame), by setting setSelectRandomImage() true or false.
I didn’t think this was the case without reading it because of being able to set X and Y - I assumed it would you let give different values.
That aside, I can’t see any reason why replacing
int imgY = (p.imageIndex - imgX) / imagesY;
With
imgY = p.imageIndex/imagesX);
Would break anything else, and then you can have any number of rows/columns you want.
Thx for reply, @JESTERRRRRR! Nice to meet u again! Let me just try to argue a bit.
I think size of texture should not affect on animation(if we have animated texture ofc), cause emitter have everything we need to configure. ImageY, ImageX, selectRandomImage, FaceNormal, etc.
Why should we rely on equality on rows and colums? If we have 3x4(my example) or 1x15(smoke.png example) equally spaced rows and columns textures, why we should edit them instead of just configure emitter?
During this, if we have texture like this
[3]
[2]
[1]
what prevent us from animate it in 1-2-3 order?
I think this
int imgY = (p.imageIndex - imgX) / imagesY;
cause it always gives 0 for any 1xX texture.
But this
imgY = p.imageIndex/imagesX
will give ok results.
Even if we take another texture like
[5][6][7][8]
[1][2][3][4]
Right?
About breaking anything else, ofc we must run tests, like we always do after changed something.
Locally i changed
int imgY = (p.imageIndex - imgX) / imagesY;
with
imgY = p.imageIndex/imagesX;
and run TestExplosionEffect and everything looks fine.
But, ofc, u r the contributor and u make final decision
Best regards.