-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Description
In 3.60 particle emitter we are now able to do things which were before possible only using custom particleClass
, like:
const emitter = this.add.particles(400, 300, 'gems', {
anim: 'prism'
...
});
or
const emitter = this.add.particles(400, 300, 'gems', {
anim: [ 'prism', 'square', 'ruby', 'square' ]
...
});
The problem here is that when running such particle system, the individual particles always start animating from frame1 of their sprite animation, which limits the variety in the resulting visual.
Here is a sample code for 'falling coins' particle system:
this.showerParticles = this.scene.make.particles({
x: 0,
y: 0,
key: LoaderAssetKeys.GAME_ATLAS,
config: {
//@ts-ignore
anim: ANIMATION_WIN_COIN,
repeat: -1,
lifespan: 5000,
x: {
onEmit: () => {
return - this.scene.cameras.main.displayWidth * 0.5 + Math.random() * this.scene.cameras.main.displayWidth;
}
},
y: {
onEmit: () => {
return -this.scene.cameras.main.displayHeight * 0.5;
}
},
angle: { min: -180, max: 180 },
speedY: 1200,
frequency: 10,
emitting: false,
}
}, false);
this.showerParticles.start();
this.add(this.showerParticles);
I used red lines to mark the repeats in the vertical pattern, which impairs overall quality of the resulting animation.
It would be great to further improve the animation particle system by introducing animStartIndex
(or similar), which would determine the frame at which each generated particle starts its animation, eg:
anim: ANIMATION_WIN_COIN,
animStartIndex: {
onEmit: () => {
return -1;
}
}
where animStartIndex
of 0 is the default, -1 means 'random'. Perhaps this param is illogical to have, and particleClass must be used instead for such functionality being available on top level. Leave that up to you guys to decide