Update the emitter to spawn particles, called automatically by engine once each frame
()
| 184 | |
| 185 | /** Update the emitter to spawn particles, called automatically by engine once each frame */ |
| 186 | update() |
| 187 | { |
| 188 | // physics sanity checks |
| 189 | ASSERT(this.angleDamping >= 0 && this.angleDamping <= 1); |
| 190 | ASSERT(this.damping >= 0 && this.damping <= 1); |
| 191 | |
| 192 | if (this.velocityInheritance) |
| 193 | { |
| 194 | // pass emitter velocity to particles |
| 195 | const p = this.velocityInheritance; |
| 196 | this.velocity.x = p * (this.pos.x - this.previousPos.x); |
| 197 | this.velocity.y = p * (this.pos.y - this.previousPos.y); |
| 198 | this.angleVelocity = p * (this.angle - this.previousAngle); |
| 199 | this.previousAngle = this.angle; |
| 200 | this.previousPos.x = this.pos.x; |
| 201 | this.previousPos.y = this.pos.y; |
| 202 | } |
| 203 | |
| 204 | // update emitter |
| 205 | if (this.isActive()) |
| 206 | { |
| 207 | // emit particles |
| 208 | if (this.emitRate && particleEmitRateScale) |
| 209 | { |
| 210 | const rate = 1/this.emitRate/particleEmitRateScale; |
| 211 | for (this.emitTimeBuffer += timeDelta; this.emitTimeBuffer > 0; this.emitTimeBuffer -= rate) |
| 212 | this.emitParticle(); |
| 213 | } |
| 214 | } |
| 215 | else if (this.particles.length === 0) |
| 216 | this.destroy(true); |
| 217 | |
| 218 | // update and remove destroyed particles |
| 219 | this.particles = this.particles.filter((p)=> |
| 220 | { |
| 221 | p.update(); |
| 222 | return !p.destroyed; |
| 223 | }); |
| 224 | |
| 225 | if (debugParticles) |
| 226 | { |
| 227 | // show emitter bounds |
| 228 | if (this.emitCircle) |
| 229 | debugCircle(this.pos, this.emitSize.x/2, '#0f0'); |
| 230 | else |
| 231 | debugRect(this.pos, this.emitSize, '#0f0', 0, this.angle); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | /** Spawn one particle |
| 236 | * @return {Particle} */ |
nothing calls this directly
no test coverage detected