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

Make particle animation state optional #6930

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/gameobjects/particles/Particle.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,19 @@ var Particle = new Class({
* It is responsible for playing, loading, queuing animations for later playback,
* mixing between animations and setting the current animation frame to this Particle.
*
* It is created only if the Particle's Emitter has at least one Animation.
*
* @name Phaser.GameObjects.Particles.Particle#anims
* @type {Phaser.Animations.AnimationState}
* @type {?Phaser.Animations.AnimationState}
* @since 3.60.0
* @see Phaser.GameObjects.Particles.ParticleEmitter#setAnim
*/
this.anims = new AnimationState(this);
this.anims = null;

if (this.emitter.anims.length > 0)
{
this.anims = new AnimationState(this);
}

/**
* A rectangle that holds the bounds of this Particle after a call to
Expand Down Expand Up @@ -590,7 +598,10 @@ var Particle = new Class({
return false;
}

this.anims.update(0, delta);
if (this.anims)
{
this.anims.update(0, delta);
}

var emitter = this.emitter;
var ops = emitter.ops;
Expand Down Expand Up @@ -783,7 +794,10 @@ var Particle = new Class({
*/
destroy: function ()
{
this.anims.destroy();
if (this.anims)
{
this.anims.destroy();
}

this.anims = null;
this.emitter = null;
Expand Down
2 changes: 2 additions & 0 deletions src/gameobjects/particles/ParticleEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,8 @@ var ParticleEmitter = new Class({
* anim: [ 'red', 'green', 'blue', 'pink', 'white' ]
* anim: { anims: [ 'red', 'green', 'blue', 'pink', 'white' ], [cycle: bool], [quantity: int] }
*
* Call this method at least once before any particles are created, or set `anim` in the Particle Emitter's configuration when creating the Emitter.
*
* @method Phaser.GameObjects.Particles.ParticleEmitter#setAnim
* @since 3.60.0
*
Expand Down