custom-pixi-particles 7.5.0 → 7.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +1000 -20
  2. package/dist/index.d.ts +3 -1
  3. package/dist/index.js +2 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/behaviour/SubEmitterBehaviour.d.ts +0 -0
  6. package/dist/lib/behaviour/SubEmitterBehaviour.js +1 -0
  7. package/dist/lib/behaviour/SubEmitterBehaviour.js.map +1 -0
  8. package/dist/lib/effects/DissolveEffect.d.ts +28 -0
  9. package/dist/lib/effects/DissolveEffect.js +204 -0
  10. package/dist/lib/effects/DissolveEffect.js.map +1 -0
  11. package/dist/lib/effects/GhostEffect.d.ts +32 -0
  12. package/dist/lib/effects/GhostEffect.js +123 -0
  13. package/dist/lib/effects/GhostEffect.js.map +1 -0
  14. package/dist/lib/effects/GlitchEffect.d.ts +25 -0
  15. package/dist/lib/effects/GlitchEffect.js +144 -0
  16. package/dist/lib/effects/GlitchEffect.js.map +1 -0
  17. package/dist/lib/effects/MagneticAssemblyEffect.d.ts +27 -0
  18. package/dist/lib/effects/MagneticAssemblyEffect.js +194 -0
  19. package/dist/lib/effects/MagneticAssemblyEffect.js.map +1 -0
  20. package/dist/lib/effects/MeltEffect.d.ts +27 -0
  21. package/dist/lib/effects/MeltEffect.js +188 -0
  22. package/dist/lib/effects/MeltEffect.js.map +1 -0
  23. package/dist/lib/effects/ShatterEffect.d.ts +40 -0
  24. package/dist/lib/effects/ShatterEffect.js +236 -0
  25. package/dist/lib/effects/ShatterEffect.js.map +1 -0
  26. package/dist/lib/effects/index.d.ts +12 -0
  27. package/dist/lib/effects/index.js +13 -0
  28. package/dist/lib/effects/index.js.map +1 -0
  29. package/dist/lib/index.d.ts +2 -0
  30. package/dist/lib/index.js +2 -0
  31. package/dist/lib/index.js.map +1 -1
  32. package/dist/lib/pixi/Renderer.js +3 -3
  33. package/dist/lib/pixi/Renderer.js.map +1 -1
  34. package/dist/lib/pixi/TestRenderer.js +3 -3
  35. package/dist/lib/pixi/TestRenderer.js.map +1 -1
  36. package/package.json +1 -1
package/README.md CHANGED
@@ -2,6 +2,30 @@
2
2
 
3
3
  **CustomPIXIParticles** is a lightweight, high-performance library designed for creating and managing customizable particle effects in **PIXI.js** applications. It offers an intuitive API, flexible configuration options, and seamless compatibility with modern PIXI.js versions, making it an essential tool for developers looking to create stunning visual effects.
4
4
 
5
+ ## 📑 Table of Contents
6
+
7
+ - [Features](#-features)
8
+ - [Demo](#-demo)
9
+ - [Installation](#️-installation)
10
+ - [Quick Start](#-quick-start)
11
+ - [API Reference](#-api-reference)
12
+ - [Configuration Guide](#-configuration-guide)
13
+ - [Emission Types](#emission-types)
14
+ - [Behaviours](#behaviours)
15
+ - [Examples](#-examples)
16
+ - [Performance Tips](#-performance-tips)
17
+ - [Troubleshooting](#-troubleshooting)
18
+ - [Special Effects](#special-effects)
19
+ - [Shatter Effect](#shatter-effect)
20
+ - [Dissolve Effect](#dissolve-effect)
21
+ - [Magnetic Assembly Effect](#magnetic-assembly-effect)
22
+ - [Ghost Effect](#ghost-effect)
23
+ - [Glitch Effect](#glitch-effect)
24
+ - [Melt Effect](#melt-effect)
25
+ - [Versions Compatibility](#️-versions-compatibility)
26
+ - [Advanced Editor](#️-advanced-editor)
27
+ - [Contributing](#-contributing)
28
+
5
29
  ---
6
30
 
7
31
  ### Support My Work
@@ -17,6 +41,7 @@ If you find **CustomPIXIParticles** useful and would like to support my work, yo
17
41
  - **Performance Optimized**: Handle thousands of particles with minimal performance overhead.
18
42
  - **PIXI.js Compatibility**: Fully compatible with **PIXI.js v8**, **PIXI.js v7**, with legacy support for v5.x and v6.x.
19
43
  - **Real-Time Customization**: Dynamically update textures, positions, configurations, and emitters on the fly.
44
+ - **Shatter Effect**: Create dramatic sprite shattering effects with realistic physics and automatic cleanup.
20
45
 
21
46
  ---
22
47
 
@@ -36,7 +61,8 @@ npm install custom-pixi-particles
36
61
  ---
37
62
 
38
63
  ## 🚀 Quick Start
39
- Import or Require
64
+
65
+ ### Import or Require
40
66
  ```javascript
41
67
  // ES6 Modules
42
68
  import customPixiParticles from 'custom-pixi-particles'
@@ -45,19 +71,79 @@ import customPixiParticles from 'custom-pixi-particles'
45
71
  const customPixiParticles = require('custom-pixi-particles')
46
72
  ```
47
73
 
48
- Create Particle Effects
74
+ ### Basic Example
49
75
  ```javascript
76
+ import { Application } from 'pixi.js'
77
+ import customPixiParticles from 'custom-pixi-particles'
78
+
79
+ // Create PIXI application
80
+ const app = new Application()
81
+ await app.init({ width: 800, height: 600 })
82
+ document.body.appendChild(app.canvas)
83
+
50
84
  // Define textures and emitter configuration
51
- const textures = ['texture1.png', 'texture2.png']
85
+ const textures = ['particle.png']
52
86
  const emitterConfig = {
53
- // Your configuration object
87
+ behaviours: [
88
+ {
89
+ priority: 10000,
90
+ enabled: true,
91
+ maxLifeTime: 2,
92
+ timeVariance: 0.5,
93
+ name: 'LifeBehaviour',
94
+ },
95
+ {
96
+ priority: 100,
97
+ enabled: true,
98
+ position: { x: 400, y: 300 },
99
+ positionVariance: { x: 0, y: 0 },
100
+ velocity: { x: 0, y: -50 },
101
+ velocityVariance: { x: 20, y: 10 },
102
+ acceleration: { x: 0, y: 50 },
103
+ accelerationVariance: { x: 0, y: 0 },
104
+ name: 'PositionBehaviour',
105
+ },
106
+ {
107
+ priority: 0,
108
+ enabled: true,
109
+ allowNegativeValues: false,
110
+ sizeStart: { x: 10, y: 10 },
111
+ sizeEnd: { x: 5, y: 5 },
112
+ startVariance: 2,
113
+ endVariance: 1,
114
+ name: 'SizeBehaviour',
115
+ },
116
+ {
117
+ priority: 0,
118
+ enabled: true,
119
+ start: { _r: 255, _g: 100, _b: 0, _alpha: 1 },
120
+ end: { _r: 255, _g: 200, _b: 0, _alpha: 0 },
121
+ startVariance: { _r: 0, _g: 0, _b: 0, _alpha: 0 },
122
+ endVariance: { _r: 0, _g: 0, _b: 0, _alpha: 0 },
123
+ sinus: false,
124
+ name: 'ColorBehaviour',
125
+ },
126
+ ],
127
+ emitController: {
128
+ _maxParticles: 1000,
129
+ _maxLife: 1,
130
+ _emitPerSecond: 50,
131
+ name: 'UniformEmission',
132
+ },
133
+ duration: -1,
134
+ alpha: 1,
135
+ blendMode: 0,
54
136
  }
55
137
 
56
138
  // Initialize particle emitter
57
- const particles = customPixiParticles.create({ textures, emitterConfig })
139
+ const particles = customPixiParticles.create({
140
+ textures,
141
+ emitterConfig,
142
+ maxParticles: 1000
143
+ })
58
144
 
59
145
  // Add emitter to the PIXI container
60
- container.addChild(particles)
146
+ app.stage.addChild(particles)
61
147
 
62
148
  // Start the emitter
63
149
  particles.play()
@@ -66,25 +152,57 @@ particles.play()
66
152
  ---
67
153
 
68
154
  ## 📖 API Reference
69
- Initializes a particle emitter.
155
+
156
+ ### Creating a Particle Emitter
157
+
158
+ Initializes a particle emitter with the specified configuration.
159
+
70
160
  ```javascript
71
161
  const particles = customPixiParticles.create({
72
- textures: [String], // Array of particle textures
73
- emitterConfig: Object, // Configuration object for the emitter
74
- animatedSpriteZeroPad: Number, // Zero-padding for animated sprite names
75
- animatedSpriteIndexToStart: Number, // Initial frame index for animated sprites
76
- finishingTextures: [String], // Textures used for particle finishing
77
- vertices: Boolean, // Use vertex mode for rendering
78
- position: Boolean, // Allow position-based behavior
79
- rotation: Boolean, // Allow rotation-based behavior
80
- uvs: Boolean, // Apply UV mapping
81
- tint: Boolean, // Apply tint to particles
82
- maxParticles: Number, // Maximum particles allowed
83
- maxFPS: Number, // Cap emitter update frequency
84
- tickerSpeed: Number, // Speed of the PIXI ticker
162
+ textures: [String], // Array of particle texture paths or PIXI.Texture objects
163
+ emitterConfig: Object, // Configuration object for the emitter (see Configuration section)
164
+ animatedSpriteZeroPad: Number, // Zero-padding for animated sprite names (default: 2)
165
+ animatedSpriteIndexToStart: Number, // Initial frame index for animated sprites (default: 0)
166
+ finishingTextures: [String], // Textures used for particle finishing animations
167
+ vertices: Boolean, // Use vertex mode for rendering (default: true)
168
+ position: Boolean, // Allow position-based behavior (default: true)
169
+ rotation: Boolean, // Allow rotation-based behavior (default: true)
170
+ uvs: Boolean, // Apply UV mapping (default: true)
171
+ tint: Boolean, // Apply tint to particles (default: true)
172
+ maxParticles: Number, // Maximum particles allowed (default: 10000)
173
+ maxFPS: Number, // Cap emitter update frequency (default: 60)
174
+ minFPS: Number, // Minimum FPS threshold (default: 30)
175
+ tickerSpeed: Number, // Speed of the PIXI ticker (default: 0.02)
85
176
  })
86
177
  ```
87
178
 
179
+ ### Configuration Object Structure
180
+
181
+ The `emitterConfig` object contains all the settings for your particle system:
182
+
183
+ ```javascript
184
+ const emitterConfig = {
185
+ // Emission Control
186
+ emitController: {
187
+ name: 'UniformEmission', // 'UniformEmission' | 'StandardEmission' | 'RandomEmission'
188
+ _maxParticles: 1000, // Maximum particles (for Standard/Random)
189
+ _maxLife: 1, // Maximum lifetime (for Standard/Random)
190
+ _emitPerSecond: 50, // Particles per second (for Uniform)
191
+ _emissionRate: 100, // Emission rate (for Standard/Random)
192
+ },
193
+
194
+ // Global Settings
195
+ duration: -1, // Emitter duration in seconds (-1 = infinite)
196
+ alpha: 1, // Global alpha (0-1)
197
+ blendMode: 0, // PIXI.js blend mode
198
+
199
+ // Behaviours Array
200
+ behaviours: [
201
+ // See Behaviours section for details
202
+ ],
203
+ }
204
+ ```
205
+
88
206
  ### Event Callbacks
89
207
  Triggered when the particle animation completes.
90
208
  ```javascript
@@ -139,6 +257,868 @@ Clears internal object pools to free memory.
139
257
  particles.clearPool()
140
258
  ```
141
259
 
260
+ ## 🎨 Special Effects
261
+
262
+ The library includes several pre-built special effects for common use cases.
263
+
264
+ ### Shatter Effect
265
+ Create a dramatic shattering effect that slices a sprite into fragments with realistic physics.
266
+
267
+ ```javascript
268
+ import { ShatterEffect } from 'custom-pixi-particles'
269
+ import { Sprite, Texture } from 'pixi.js'
270
+
271
+ // Create a sprite to shatter
272
+ const sprite = new Sprite(Texture.from('my-image.png'))
273
+ sprite.anchor.set(0.5, 0.5)
274
+ sprite.x = 400
275
+ sprite.y = 300
276
+
277
+ // Create shatter effect with custom options
278
+ const shatterEffect = new ShatterEffect(sprite, {
279
+ gridCols: 10, // Number of horizontal grid divisions (default: 8)
280
+ gridRows: 10, // Number of vertical grid divisions (default: 8)
281
+ mode: 'radial', // 'radial', 'directional', or 'swirl'.
282
+ explosionPower: 1000, // Velocity of the fragments (default: 1000)
283
+ enableRotation: true, // Whether fragments spin (default: true)
284
+ rotationStrength: 1.0, // Multiplier for fragment spin speed (default: 1.0)
285
+ gravity: 600, // Gravity force applied to fragments (default: 500)
286
+ friction: 0.96, // Velocity air resistance (default: 0.96)
287
+ turbulence: 0.2, // Randomness of fragment angles (default: 0.2)
288
+ lifetime: 2.5, // Lifetime of fragments in seconds (default: 2)
289
+ fadeOutDuration: 0.3, // Fade out duration at the end of lifetime (default: 0.3)
290
+ endTint: 0xFFFFFF // Color to lerp toward as fragments die (default: 0xFFFFFF)
291
+ })
292
+
293
+ // Add to stage
294
+ app.stage.addChild(shatterEffect)
295
+
296
+ // Trigger explosion with optional completion callback
297
+ shatterEffect.Explode().then(() => {
298
+ console.log("Boom! Animation complete.");
299
+ effect.destroy();
300
+ });
301
+
302
+ // Or Simple Usage (Static Method)
303
+ await ShatterEffect.shatter(mySprite, {
304
+ gridCols: 10,
305
+ gridRows: 10,
306
+ explosionPower: 1200,
307
+ enableRotation: true,
308
+ rotationStrength: 1.5
309
+ });
310
+ ```
311
+
312
+ **ShatterEffect Methods:**
313
+ - `Explode(onComplete?)` - Triggers the shatter animation. Optionally accepts a callback when animation completes.
314
+ - `reset()` - Resets the effect to its initial state, allowing it to be triggered again.
315
+ - `destroy()` - Destroys the effect and cleans up all resources.
316
+
317
+ **Features:**
318
+ - Automatically slices sprites into a grid of fragments
319
+ - Each fragment radiates outward from the sprite's center with random variance
320
+ - Realistic physics with gravity and rotation
321
+ - Automatic cleanup and memory management using object pooling
322
+ - Smooth fade-out animation at the end of fragment lifetime
323
+
324
+ ### Dissolve Effect
325
+ Create a smooth dissolving effect that breaks sprites into pixelated fragments that drift away.
326
+
327
+ ```javascript
328
+ import { DissolveEffect } from 'custom-pixi-particles'
329
+ import { Sprite, Texture } from 'pixi.js'
330
+
331
+ const sprite = new Sprite(Texture.from('my-image.png'))
332
+ sprite.anchor.set(0.5, 0.5)
333
+ sprite.x = 400
334
+ sprite.y = 300
335
+
336
+ const dissolveEffect = new DissolveEffect(sprite, {
337
+ pixelSize: 2, // Size of each fragment (default: 2)
338
+ edgeSoftness: 0.5, // Softness of dissolve edges (default: 0.5)
339
+ driftStrength: 50, // How far fragments drift (default: 50)
340
+ noiseIntensity: 0.3, // Randomness in dissolve pattern (default: 0.3)
341
+ lifetime: 2.5, // How long fragments last (default: 2.5)
342
+ fadeOutDuration: 0.3, // Fade out time at end (default: 0.3)
343
+ direction: 'center-out', // 'left-to-right' | 'right-to-left' | 'top-to-bottom' | 'bottom-to-top' | 'center-out' (default: 'center-out')
344
+ windAngle: 0 // Wind direction in radians (default: 0)
345
+ })
346
+
347
+ app.stage.addChild(dissolveEffect)
348
+
349
+ // Trigger dissolve with optional completion callback
350
+ dissolveEffect.dissolve().then(() => {
351
+ console.log("Dissolve complete!")
352
+ dissolveEffect.destroy()
353
+ })
354
+ ```
355
+
356
+ **DissolveEffect Methods:**
357
+ - `dissolve(onComplete?)` - Triggers the dissolve animation. Optionally accepts a callback when animation completes.
358
+ - `reset()` - Resets the effect to its initial state.
359
+ - `destroy()` - Destroys the effect and cleans up all resources.
360
+
361
+ ### Magnetic Assembly Effect
362
+ Create an effect where fragments assemble together to form a sprite, with various assembly modes.
363
+
364
+ ```javascript
365
+ import { MagneticAssemblyEffect } from 'custom-pixi-particles'
366
+ import { Sprite, Texture } from 'pixi.js'
367
+
368
+ const sprite = new Sprite(Texture.from('my-image.png'))
369
+ sprite.anchor.set(0.5, 0.5)
370
+ sprite.x = 400
371
+ sprite.y = 300
372
+
373
+ const assemblyEffect = new MagneticAssemblyEffect(sprite, {
374
+ gridCols: 10, // Number of horizontal divisions (default: 10)
375
+ gridRows: 10, // Number of vertical divisions (default: 10)
376
+ duration: 1.5, // Assembly duration in seconds (default: 1.5)
377
+ easing: 'back.out', // Easing function: 'back.out' | 'power1.inOut' | 'bounce.out' | 'linear' (default: 'back.out')
378
+ scatterRange: 200, // How far fragments start from target (default: 200)
379
+ stagger: 0.1, // Delay between fragments (0-1, default: 0.1)
380
+ mode: 'random-scatter', // 'random-scatter' | 'from-center' | 'off-screen' | 'vortex' (default: 'random-scatter')
381
+ startAlpha: 0 // Initial alpha of fragments (default: 0)
382
+ })
383
+
384
+ app.stage.addChild(assemblyEffect)
385
+
386
+ // Trigger assembly
387
+ assemblyEffect.assemble().then(() => {
388
+ console.log("Assembly complete!")
389
+ })
390
+ ```
391
+
392
+ **MagneticAssemblyEffect Methods:**
393
+ - `assemble(onComplete?)` - Triggers the assembly animation. Optionally accepts a callback when animation completes.
394
+ - `reset()` - Resets the effect to its initial state.
395
+ - `destroy()` - Destroys the effect and cleans up all resources.
396
+
397
+ ### Ghost Effect
398
+ Create a trailing ghost/echo effect that follows a sprite's movement, perfect for motion trails.
399
+
400
+ ```javascript
401
+ import { GhostEffect } from 'custom-pixi-particles'
402
+ import { Sprite, Texture, BLEND_MODES } from 'pixi.js'
403
+
404
+ const sprite = new Sprite(Texture.from('my-image.png'))
405
+ sprite.anchor.set(0.5, 0.5)
406
+
407
+ const ghostEffect = new GhostEffect(sprite, {
408
+ spawnInterval: 0.05, // Seconds between echo spawns (default: 0.05)
409
+ ghostLifetime: 0.5, // How long each echo stays visible (default: 0.5)
410
+ startAlpha: 0.6, // Initial transparency (default: 0.6)
411
+ endAlpha: 0, // Final transparency (default: 0)
412
+ startTint: 0xFFFFFF, // Initial color (default: 0xFFFFFF)
413
+ endTint: 0x00AAFF, // Target color (default: 0x00AAFF)
414
+ blendMode: BLEND_MODES.ADD, // Blend mode (default: BLEND_MODES.NORMAL)
415
+ maxGhosts: 20 // Maximum active echoes (default: 20)
416
+ })
417
+
418
+ app.stage.addChild(ghostEffect)
419
+ app.stage.addChild(sprite)
420
+
421
+ // Start tracking (ghosts will follow sprite movement)
422
+ ghostEffect.start()
423
+
424
+ // Stop tracking
425
+ ghostEffect.stop()
426
+
427
+ // Clean up
428
+ ghostEffect.destroy()
429
+ ```
430
+
431
+ **GhostEffect Methods:**
432
+ - `start()` - Begins generating ghost echoes.
433
+ - `stop()` - Stops generating new echoes (existing ones fade out).
434
+ - `destroy()` - Destroys the effect and cleans up all resources.
435
+
436
+ ### Glitch Effect
437
+ Create a digital glitch effect with RGB splitting, flickering, and horizontal displacement.
438
+
439
+ ```javascript
440
+ import { GlitchEffect } from 'custom-pixi-particles'
441
+ import { Sprite, Texture } from 'pixi.js'
442
+
443
+ const sprite = new Sprite(Texture.from('my-image.png'))
444
+ sprite.anchor.set(0.5, 0.5)
445
+ sprite.x = 400
446
+ sprite.y = 300
447
+
448
+ const glitchEffect = new GlitchEffect(sprite, {
449
+ slices: 15, // Number of horizontal strips (default: 15)
450
+ offsetRange: 30, // Max horizontal shift in pixels (default: 30)
451
+ flickerIntensity: 0.3, // Probability of slice disappearing (0-1, default: 0.3)
452
+ rgbSplit: true, // Enable RGB channel separation (default: true)
453
+ rgbOffset: 10, // How far R/G/B channels drift apart (default: 10)
454
+ duration: 1.0, // How long the glitch lasts (default: 1.0)
455
+ refreshRate: 0.05 // How often patterns change in seconds (default: 0.05)
456
+ })
457
+
458
+ app.stage.addChild(glitchEffect)
459
+
460
+ // Trigger glitch
461
+ glitchEffect.glitch().then(() => {
462
+ console.log("Glitch complete!")
463
+ glitchEffect.destroy()
464
+ })
465
+ ```
466
+
467
+ **GlitchEffect Methods:**
468
+ - `glitch(onComplete?)` - Triggers the glitch animation. Optionally accepts a callback when animation completes.
469
+ - `reset()` - Resets the effect to its initial state.
470
+ - `destroy()` - Destroys the effect and cleans up all resources.
471
+
472
+ ### Melt Effect
473
+ Create a liquid melting effect where sprites appear to melt and drip downward with realistic physics.
474
+
475
+ ```javascript
476
+ import { MeltEffect } from 'custom-pixi-particles'
477
+ import { Sprite, Texture } from 'pixi.js'
478
+
479
+ const sprite = new Sprite(Texture.from('my-image.png'))
480
+ sprite.anchor.set(0.5, 0.5)
481
+ sprite.x = 400
482
+ sprite.y = 300
483
+
484
+ const meltEffect = new MeltEffect(sprite, {
485
+ gridCols: 10, // Number of horizontal divisions (default: 10)
486
+ gridRows: 10, // Number of vertical divisions (default: 10)
487
+ gravity: 1200, // Downward force (default: 1200)
488
+ viscosity: 0.98, // Friction/resistance (default: 0.98)
489
+ horizontalSpread: 50, // Sideways movement amount (default: 50)
490
+ duration: 3.0, // Effect duration (default: 3.0)
491
+ blurAmount: 6, // Liquid blur intensity (default: 6)
492
+ threshold: 0.5 // Alpha clipping point 0-1 (default: 0.5)
493
+ })
494
+
495
+ app.stage.addChild(meltEffect)
496
+
497
+ // Trigger melt
498
+ meltEffect.melt().then(() => {
499
+ console.log("Melt complete!")
500
+ meltEffect.destroy()
501
+ })
502
+ ```
503
+
504
+ **MeltEffect Methods:**
505
+ - `melt(onComplete?)` - Triggers the melt animation. Optionally accepts a callback when animation completes.
506
+ - `reset()` - Resets the effect to its initial state.
507
+ - `destroy()` - Destroys the effect and cleans up all resources.
508
+
509
+ ---
510
+
511
+ ## 📚 Configuration Guide
512
+
513
+ ### Emission Types
514
+
515
+ The library supports three emission types that control how particles are emitted:
516
+
517
+ #### 1. Uniform Emission
518
+ Particles are emitted at a consistent rate per second.
519
+
520
+ ```javascript
521
+ emitController: {
522
+ name: 'UniformEmission',
523
+ _emitPerSecond: 50, // Particles emitted per second
524
+ }
525
+ ```
526
+
527
+ #### 2. Standard Emission
528
+ Particles are emitted up to a maximum count with a defined rate.
529
+
530
+ ```javascript
531
+ emitController: {
532
+ name: 'StandardEmission',
533
+ _maxParticles: 1000, // Maximum particles that can exist
534
+ _maxLife: 1, // Maximum lifetime
535
+ _emissionRate: 100, // Emission rate
536
+ }
537
+ ```
538
+
539
+ #### 3. Random Emission
540
+ Particles are emitted randomly with variance.
541
+
542
+ ```javascript
543
+ emitController: {
544
+ name: 'RandomEmission',
545
+ _maxParticles: 1000,
546
+ _maxLife: 1,
547
+ _emissionRate: 100,
548
+ }
549
+ ```
550
+
551
+ ### Behaviours
552
+
553
+ Behaviours define how particles behave throughout their lifetime. Each behaviour has a `priority` (higher = processed first) and can be `enabled` or disabled.
554
+
555
+ #### Life Behaviour
556
+ Controls particle lifetime.
557
+
558
+ ```javascript
559
+ {
560
+ priority: 10000, // High priority (processed first)
561
+ enabled: true,
562
+ maxLifeTime: 2, // Maximum lifetime in seconds
563
+ timeVariance: 0.5, // Random variance in lifetime
564
+ name: 'LifeBehaviour',
565
+ }
566
+ ```
567
+
568
+ #### Position Behaviour
569
+ Controls particle position, velocity, and acceleration.
570
+
571
+ ```javascript
572
+ {
573
+ priority: 100,
574
+ enabled: true,
575
+ position: { x: 400, y: 300 }, // Initial position
576
+ positionVariance: { x: 10, y: 10 }, // Position randomness
577
+ velocity: { x: 0, y: -50 }, // Initial velocity
578
+ velocityVariance: { x: 20, y: 10 }, // Velocity randomness
579
+ acceleration: { x: 0, y: 50 }, // Constant acceleration
580
+ accelerationVariance: { x: 0, y: 0 }, // Acceleration randomness
581
+ name: 'PositionBehaviour',
582
+ }
583
+ ```
584
+
585
+ #### Spawn Behaviour
586
+ Defines where and how particles spawn. Supports multiple spawn types.
587
+
588
+ ```javascript
589
+ {
590
+ priority: 100,
591
+ enabled: true,
592
+ customPoints: [
593
+ {
594
+ spawnType: 'Rectangle', // See Spawn Types below
595
+ position: { x: 0, y: 0 },
596
+ positionVariance: { x: 100, y: 100 },
597
+ // ... spawn type specific properties
598
+ },
599
+ ],
600
+ trailingEnabled: false, // Enable trail effects
601
+ spawnAlongTrail: false, // Spawn along entire trail
602
+ trailSpeed: 1, // Trail animation speed
603
+ name: 'SpawnBehaviour',
604
+ }
605
+ ```
606
+
607
+ **Available Spawn Types:**
608
+ - `Rectangle` - Uniform distribution in a rectangular area
609
+ - `Ring` - Circular particle arrangement
610
+ - `Star` - Star-shaped distribution with configurable points
611
+ - `Grid` - Organized grid with rows and columns
612
+ - `Word` - Particles form text/word shapes
613
+ - `Sphere` - 3D sphere-shaped spawning
614
+ - `Cone` - Conical distribution with customizable angles
615
+ - `Frame` - Particles along frame edges
616
+ - `FrameRectangle` - Rectangular frame outline
617
+ - `Bezier` - Particles follow Bezier curve paths
618
+ - `Helix` - Spiral helix with adjustable pitch and turns
619
+ - `Heart` - Heart-shaped formations
620
+ - `Lissajous` - Complex figure-eight-like paths
621
+ - `Spring` - Spring-like patterns with coiled loops
622
+ - `Path` - Custom path defined by points
623
+ - `Oval` - Elliptical distributions
624
+
625
+ #### Size Behaviour
626
+ Controls particle size over time.
627
+
628
+ ```javascript
629
+ {
630
+ priority: 0,
631
+ enabled: true,
632
+ allowNegativeValues: false,
633
+ sizeStart: { x: 10, y: 10 }, // Initial size
634
+ sizeEnd: { x: 5, y: 5 }, // Final size
635
+ startVariance: 2, // Size start randomness
636
+ endVariance: 1, // Size end randomness
637
+ name: 'SizeBehaviour',
638
+ }
639
+ ```
640
+
641
+ #### Color Behaviour
642
+ Controls particle color and alpha over time.
643
+
644
+ ```javascript
645
+ {
646
+ priority: 0,
647
+ enabled: true,
648
+ start: { _r: 255, _g: 100, _b: 0, _alpha: 1 }, // Start color (RGBA)
649
+ end: { _r: 255, _g: 200, _b: 0, _alpha: 0 }, // End color (RGBA)
650
+ startVariance: { _r: 0, _g: 0, _b: 0, _alpha: 0 }, // Color start variance
651
+ endVariance: { _r: 0, _g: 0, _b: 0, _alpha: 0 }, // Color end variance
652
+ sinus: false, // Use sine wave interpolation
653
+ name: 'ColorBehaviour',
654
+ }
655
+ ```
656
+
657
+ #### Rotation Behaviour
658
+ Controls particle rotation.
659
+
660
+ ```javascript
661
+ {
662
+ priority: 0,
663
+ enabled: true,
664
+ rotation: 0, // Initial rotation in radians
665
+ variance: 0.2, // Rotation randomness
666
+ name: 'RotationBehaviour',
667
+ }
668
+ ```
669
+
670
+ #### Angular Velocity Behaviour
671
+ Controls particle spin speed.
672
+
673
+ ```javascript
674
+ {
675
+ priority: 0,
676
+ enabled: true,
677
+ angularVelocity: 1, // Rotation speed
678
+ variance: 0.5, // Speed randomness
679
+ name: 'AngularVelocityBehaviour',
680
+ }
681
+ ```
682
+
683
+ #### Emit Direction Behaviour
684
+ Controls initial emission direction.
685
+
686
+ ```javascript
687
+ {
688
+ priority: 0,
689
+ enabled: true,
690
+ angle: 0, // Emission angle in radians
691
+ variance: 0.5, // Angle randomness
692
+ name: 'EmitDirectionBehaviour',
693
+ }
694
+ ```
695
+
696
+ #### Turbulence Behaviour
697
+ Adds random motion to particles.
698
+
699
+ ```javascript
700
+ {
701
+ priority: 0,
702
+ enabled: true,
703
+ strength: 10, // Turbulence strength
704
+ scale: 0.1, // Noise scale
705
+ speed: 1, // Turbulence speed
706
+ name: 'TurbulenceBehaviour',
707
+ }
708
+ ```
709
+
710
+ #### Collision Behaviour
711
+ Handles particle collisions with boundaries.
712
+
713
+ ```javascript
714
+ {
715
+ priority: 0,
716
+ enabled: true,
717
+ bounce: 0.5, // Bounce coefficient (0-1)
718
+ bounds: { // Collision boundaries
719
+ x: 0,
720
+ y: 0,
721
+ width: 800,
722
+ height: 600,
723
+ },
724
+ name: 'CollisionBehaviour',
725
+ }
726
+ ```
727
+
728
+ #### Attraction/Repulsion Behaviour
729
+ Particles attract or repel from points.
730
+
731
+ ```javascript
732
+ {
733
+ priority: 0,
734
+ enabled: true,
735
+ points: [
736
+ {
737
+ x: 400,
738
+ y: 300,
739
+ strength: 100, // Positive = attraction, Negative = repulsion
740
+ radius: 200, // Effect radius
741
+ },
742
+ ],
743
+ name: 'AttractionRepulsionBehaviour',
744
+ }
745
+ ```
746
+
747
+ #### Noise-Based Motion Behaviour
748
+ Uses Perlin noise for organic movement.
749
+
750
+ ```javascript
751
+ {
752
+ priority: 0,
753
+ enabled: true,
754
+ strength: 50, // Noise strength
755
+ scale: 0.01, // Noise scale
756
+ speed: 1, // Animation speed
757
+ name: 'NoiseBasedMotionBehaviour',
758
+ }
759
+ ```
760
+
761
+ #### Force Fields Behaviour
762
+ Applies force fields to particles.
763
+
764
+ ```javascript
765
+ {
766
+ priority: 0,
767
+ enabled: true,
768
+ fields: [
769
+ {
770
+ type: 'vortex', // 'vortex' | 'wind' | 'gravity'
771
+ position: { x: 400, y: 300 },
772
+ strength: 100,
773
+ radius: 200,
774
+ },
775
+ ],
776
+ name: 'ForceFieldsBehaviour',
777
+ }
778
+ ```
779
+
780
+ #### Timeline Behaviour
781
+ Controls particle properties over time with keyframes.
782
+
783
+ ```javascript
784
+ {
785
+ priority: 0,
786
+ enabled: true,
787
+ keyframes: [
788
+ { time: 0, property: 'alpha', value: 1 },
789
+ { time: 0.5, property: 'alpha', value: 0.5 },
790
+ { time: 1, property: 'alpha', value: 0 },
791
+ ],
792
+ name: 'TimelineBehaviour',
793
+ }
794
+ ```
795
+
796
+ #### Grouping Behaviour
797
+ Groups particles together.
798
+
799
+ ```javascript
800
+ {
801
+ priority: 0,
802
+ enabled: true,
803
+ groupSize: 5, // Particles per group
804
+ cohesion: 0.5, // Group cohesion strength
805
+ name: 'GroupingBehaviour',
806
+ }
807
+ ```
808
+
809
+ #### Sound Reactive Behaviour
810
+ Reacts to audio input.
811
+
812
+ ```javascript
813
+ {
814
+ priority: 0,
815
+ enabled: true,
816
+ audioSource: audioContext, // Web Audio API source
817
+ sensitivity: 1, // Reaction sensitivity
818
+ frequencyRange: [0, 1000], // Frequency range to react to
819
+ name: 'SoundReactiveBehaviour',
820
+ }
821
+ ```
822
+
823
+ #### Light Effect Behaviour
824
+ Adds lighting effects to particles.
825
+
826
+ ```javascript
827
+ {
828
+ priority: 0,
829
+ enabled: true,
830
+ lights: [
831
+ {
832
+ position: { x: 400, y: 300 },
833
+ intensity: 1,
834
+ radius: 200,
835
+ color: 0xFFFFFF,
836
+ },
837
+ ],
838
+ name: 'LightEffectBehaviour',
839
+ }
840
+ ```
841
+
842
+ #### Stretch Behaviour
843
+ Stretches particles based on velocity.
844
+
845
+ ```javascript
846
+ {
847
+ priority: 0,
848
+ enabled: true,
849
+ stretchFactor: 2, // Stretch multiplier
850
+ minStretch: 1, // Minimum stretch
851
+ maxStretch: 5, // Maximum stretch
852
+ name: 'StretchBehaviour',
853
+ }
854
+ ```
855
+
856
+ #### Temperature Behaviour
857
+ Simulates temperature effects.
858
+
859
+ ```javascript
860
+ {
861
+ priority: 0,
862
+ enabled: true,
863
+ temperature: 100, // Base temperature
864
+ variance: 20, // Temperature variance
865
+ name: 'TemperatureBehaviour',
866
+ }
867
+ ```
868
+
869
+ #### Move To Point Behaviour
870
+ Moves particles toward specific points.
871
+
872
+ ```javascript
873
+ {
874
+ priority: 0,
875
+ enabled: true,
876
+ target: { x: 400, y: 300 },
877
+ speed: 100, // Movement speed
878
+ easing: 0.1, // Easing factor
879
+ name: 'MoveToPointBehaviour',
880
+ }
881
+ ```
882
+
883
+ ---
884
+
885
+ ## 💡 Examples
886
+
887
+ ### Fire Effect
888
+ ```javascript
889
+ const fireConfig = {
890
+ behaviours: [
891
+ {
892
+ priority: 10000,
893
+ enabled: true,
894
+ maxLifeTime: 1.5,
895
+ timeVariance: 0.5,
896
+ name: 'LifeBehaviour',
897
+ },
898
+ {
899
+ priority: 100,
900
+ enabled: true,
901
+ position: { x: 400, y: 500 },
902
+ positionVariance: { x: 20, y: 0 },
903
+ velocity: { x: 0, y: -80 },
904
+ velocityVariance: { x: 15, y: 20 },
905
+ acceleration: { x: 0, y: -30 },
906
+ name: 'PositionBehaviour',
907
+ },
908
+ {
909
+ priority: 0,
910
+ enabled: true,
911
+ sizeStart: { x: 20, y: 20 },
912
+ sizeEnd: { x: 5, y: 5 },
913
+ name: 'SizeBehaviour',
914
+ },
915
+ {
916
+ priority: 0,
917
+ enabled: true,
918
+ start: { _r: 255, _g: 100, _b: 0, _alpha: 1 },
919
+ end: { _r: 255, _g: 0, _b: 0, _alpha: 0 },
920
+ name: 'ColorBehaviour',
921
+ },
922
+ ],
923
+ emitController: {
924
+ _emitPerSecond: 100,
925
+ name: 'UniformEmission',
926
+ },
927
+ duration: -1,
928
+ alpha: 1,
929
+ blendMode: 2, // ADD blend mode
930
+ }
931
+
932
+ const fire = customPixiParticles.create({
933
+ textures: ['flame.png'],
934
+ emitterConfig: fireConfig,
935
+ })
936
+ ```
937
+
938
+ ### Explosion Effect
939
+ ```javascript
940
+ const explosionConfig = {
941
+ behaviours: [
942
+ {
943
+ priority: 10000,
944
+ enabled: true,
945
+ maxLifeTime: 0.5,
946
+ timeVariance: 0.2,
947
+ name: 'LifeBehaviour',
948
+ },
949
+ {
950
+ priority: 100,
951
+ enabled: true,
952
+ customPoints: [{
953
+ spawnType: 'Ring',
954
+ radius: 0,
955
+ position: { x: 400, y: 300 },
956
+ }],
957
+ velocity: { x: 0, y: 0 },
958
+ velocityVariance: { x: 200, y: 200 },
959
+ acceleration: { x: 0, y: 100 },
960
+ name: 'SpawnBehaviour',
961
+ },
962
+ {
963
+ priority: 100,
964
+ enabled: true,
965
+ position: { x: 400, y: 300 },
966
+ name: 'PositionBehaviour',
967
+ },
968
+ {
969
+ priority: 0,
970
+ enabled: true,
971
+ sizeStart: { x: 15, y: 15 },
972
+ sizeEnd: { x: 5, y: 5 },
973
+ name: 'SizeBehaviour',
974
+ },
975
+ {
976
+ priority: 0,
977
+ enabled: true,
978
+ start: { _r: 255, _g: 255, _b: 0, _alpha: 1 },
979
+ end: { _r: 255, _g: 0, _b: 0, _alpha: 0 },
980
+ name: 'ColorBehaviour',
981
+ },
982
+ ],
983
+ emitController: {
984
+ _maxParticles: 500,
985
+ _maxLife: 1,
986
+ _emissionRate: 1000,
987
+ name: 'StandardEmission',
988
+ },
989
+ duration: 0.1,
990
+ }
991
+
992
+ const explosion = customPixiParticles.create({
993
+ textures: ['spark.png'],
994
+ emitterConfig: explosionConfig,
995
+ })
996
+ explosion.play()
997
+ ```
998
+
999
+ ### Text Effect
1000
+ ```javascript
1001
+ const textConfig = {
1002
+ behaviours: [
1003
+ {
1004
+ priority: 10000,
1005
+ enabled: true,
1006
+ maxLifeTime: 2,
1007
+ name: 'LifeBehaviour',
1008
+ },
1009
+ {
1010
+ priority: 100,
1011
+ enabled: true,
1012
+ customPoints: [{
1013
+ spawnType: 'Word',
1014
+ word: 'Hello',
1015
+ fontSize: 100,
1016
+ fontSpacing: 5,
1017
+ particleDensity: 1,
1018
+ position: { x: 400, y: 300 },
1019
+ }],
1020
+ velocity: { x: 0, y: 0 },
1021
+ name: 'SpawnBehaviour',
1022
+ },
1023
+ {
1024
+ priority: 0,
1025
+ enabled: true,
1026
+ sizeStart: { x: 3, y: 3 },
1027
+ sizeEnd: { x: 3, y: 3 },
1028
+ name: 'SizeBehaviour',
1029
+ },
1030
+ {
1031
+ priority: 0,
1032
+ enabled: true,
1033
+ start: { _r: 255, _g: 255, _b: 255, _alpha: 1 },
1034
+ end: { _r: 255, _g: 255, _b: 255, _alpha: 1 },
1035
+ name: 'ColorBehaviour',
1036
+ },
1037
+ ],
1038
+ emitController: {
1039
+ _maxParticles: 1000,
1040
+ _maxLife: 1,
1041
+ _emissionRate: 500,
1042
+ name: 'StandardEmission',
1043
+ },
1044
+ duration: 0.1,
1045
+ }
1046
+ ```
1047
+
1048
+ ---
1049
+
1050
+ ## ⚡ Performance Tips
1051
+
1052
+ 1. **Limit Particle Count**: Use `maxParticles` to cap the number of active particles
1053
+ 2. **Optimize Textures**: Use small, optimized texture files
1054
+ 3. **Disable Unused Features**: Set `vertices`, `rotation`, `tint` to `false` if not needed
1055
+ 4. **Use Object Pooling**: The library automatically pools particles - avoid creating new emitters frequently
1056
+ 5. **FPS Capping**: Use `maxFPS` and `minFPS` to control update frequency
1057
+ 6. **Batch Updates**: Update multiple emitters in a single frame when possible
1058
+ 7. **Clean Up**: Call `destroy()` and `clearPool()` when done with emitters
1059
+
1060
+ ---
1061
+
1062
+ ## 🐛 Troubleshooting
1063
+
1064
+ ### Particles Not Appearing
1065
+ - Check that textures are loaded before creating the emitter
1066
+ - Verify `emitterConfig` structure is correct
1067
+ - Ensure emitter is added to the stage and `play()` is called
1068
+ - Check that behaviours are enabled
1069
+
1070
+ ### Performance Issues
1071
+ - Reduce `maxParticles` count
1072
+ - Lower `_emitPerSecond` or `_emissionRate`
1073
+ - Disable unused behaviours
1074
+ - Use simpler spawn types (avoid complex paths)
1075
+
1076
+ ### Particles Not Following Expected Path
1077
+ - Check behaviour priorities (higher priority = processed first)
1078
+ - Verify position, velocity, and acceleration values
1079
+ - Ensure SpawnBehaviour is configured correctly for your spawn type
1080
+
1081
+ ### Memory Leaks
1082
+ - Always call `destroy()` on emitters when done
1083
+ - Use `clearPool()` periodically for long-running applications
1084
+ - Avoid creating new emitters every frame
1085
+
1086
+ ---
1087
+
1088
+ ## 🎯 Common Use Cases
1089
+
1090
+ ### Game Effects
1091
+ - **Explosions**: Use burst emission with high velocity variance
1092
+ - **Fire/Smoke**: Continuous emission with upward velocity and color gradients
1093
+ - **Magic Spells**: Combine multiple emitters with different spawn types
1094
+ - **Hit Effects**: Short-duration bursts with radial emission
1095
+ - **Trails**: Use GhostEffect for character movement trails
1096
+
1097
+ ### UI Effects
1098
+ - **Button Hover**: Subtle particle bursts on interaction
1099
+ - **Loading Animations**: Continuous particle streams
1100
+ - **Transitions**: Dissolve or shatter effects for scene changes
1101
+ - **Notifications**: Brief particle celebrations
1102
+
1103
+ ### Visual Effects
1104
+ - **Text Animations**: Use Word spawn type for text effects
1105
+ - **Background Ambiance**: Low-intensity continuous emitters
1106
+ - **Weather Effects**: Rain, snow, or leaves with appropriate physics
1107
+ - **Particle Art**: Create artistic patterns with custom spawn paths
1108
+
1109
+ ---
1110
+
1111
+ ## 🔧 Best Practices
1112
+
1113
+ 1. **Start Simple**: Begin with basic behaviours and add complexity gradually
1114
+ 2. **Use the Editor**: Leverage the visual editor to prototype effects quickly
1115
+ 3. **Profile Performance**: Monitor FPS and particle counts during development
1116
+ 4. **Reuse Configurations**: Save and reuse emitter configs for consistency
1117
+ 5. **Test on Target Devices**: Performance varies across devices - test early
1118
+ 6. **Clean Up Properly**: Always destroy emitters when switching scenes
1119
+ 7. **Optimize Textures**: Use texture atlases and appropriate sizes
1120
+ 8. **Layer Effects**: Combine multiple emitters for complex effects
1121
+
142
1122
  ---
143
1123
 
144
1124
  ## 🖥️ Versions Compatibility