* 发射粒子 * Emit particles * * @param pool - Particle pool * @param dt - Delta time in seconds * @param worldX - World position X * @param worldY - World position Y * @param worldRotation - World rotation in radians (applied to emission direction) * @param worldS
(
pool: ParticlePool,
dt: number,
worldX: number,
worldY: number,
worldRotation: number = 0,
worldScaleX: number = 1,
worldScaleY: number = 1
)
| 165 | * @returns Number of particles emitted |
| 166 | */ |
| 167 | emit( |
| 168 | pool: ParticlePool, |
| 169 | dt: number, |
| 170 | worldX: number, |
| 171 | worldY: number, |
| 172 | worldRotation: number = 0, |
| 173 | worldScaleX: number = 1, |
| 174 | worldScaleY: number = 1 |
| 175 | ): number { |
| 176 | if (!this._isEmitting) return 0; |
| 177 | |
| 178 | let emitted = 0; |
| 179 | |
| 180 | if (this.config.burstCount > 0) { |
| 181 | // 爆发模式 | Burst mode |
| 182 | for (let i = 0; i < this.config.burstCount; i++) { |
| 183 | const p = pool.spawn(); |
| 184 | if (p) { |
| 185 | this._initParticle(p, worldX, worldY, worldRotation, worldScaleX, worldScaleY); |
| 186 | emitted++; |
| 187 | } |
| 188 | } |
| 189 | this._isEmitting = false; |
| 190 | } else { |
| 191 | // 持续发射 | Continuous emission |
| 192 | this._emissionAccumulator += this.config.emissionRate * dt; |
| 193 | while (this._emissionAccumulator >= 1) { |
| 194 | const p = pool.spawn(); |
| 195 | if (p) { |
| 196 | this._initParticle(p, worldX, worldY, worldRotation, worldScaleX, worldScaleY); |
| 197 | emitted++; |
| 198 | } |
| 199 | this._emissionAccumulator -= 1; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | return emitted; |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * 立即爆发发射 |
no test coverage detected