diff --git a/packages/core/src/particle/ParticleGenerator.ts b/packages/core/src/particle/ParticleGenerator.ts index 744dde9bc..1f3baa89c 100644 --- a/packages/core/src/particle/ParticleGenerator.ts +++ b/packages/core/src/particle/ParticleGenerator.ts @@ -121,6 +121,8 @@ export class ParticleGenerator { private _firstActiveTransformedBoundingBox = 0; @ignoreClone private _firstFreeTransformedBoundingBox = 0; + @ignoreClone + private _playStartDelay = 0; /** * Whether the particle generator is contain alive or is still creating particles. @@ -187,6 +189,8 @@ export class ParticleGenerator { if (this.useAutoRandomSeed) { this._resetGlobalRandSeed(Math.floor(Math.random() * 0xffffffff)); // 2^32 - 1 } + + this._playStartDelay = this.main.startDelay.evaluate(undefined, this.main._startDelayRand.random()); } } @@ -266,8 +270,20 @@ export class ParticleGenerator { const { main, emission } = this; const duration = main.duration; const lastPlayTime = this._playTime; + const deltaTime = elapsedTime * main.simulationSpeed; - this._playTime += elapsedTime * main.simulationSpeed; + // Process start delay time + if (this._playStartDelay > 0) { + const remainingDelay = (this._playStartDelay -= deltaTime); + if (remainingDelay < 0) { + this._playTime -= remainingDelay; + this._playStartDelay = 0; + } else { + return; + } + } + + this._playTime += deltaTime; this._retireActiveParticles(); this._freeRetiredParticles(); diff --git a/packages/core/src/particle/modules/MainModule.ts b/packages/core/src/particle/modules/MainModule.ts index 7778ae27c..94a73610e 100644 --- a/packages/core/src/particle/modules/MainModule.ts +++ b/packages/core/src/particle/modules/MainModule.ts @@ -63,6 +63,9 @@ export class MainModule implements ICustomClone { _maxParticleBuffer = 1000; /** @internal */ @ignoreClone + readonly _startDelayRand = new Rand(0, ParticleRandomSubSeeds.StartDelay); + /** @internal */ + @ignoreClone readonly _startSpeedRand = new Rand(0, ParticleRandomSubSeeds.StartSpeed); /** @internal */ @ignoreClone