1+ var BlendModes = require ( '../../renderer/BlendModes' ) ;
12var Class = require ( '../../utils/Class' ) ;
23var Components = require ( '../components' ) ;
34var Easing = require ( '../../math/easing' ) ;
45var GetEaseFunction = require ( '../../tweens/builder/GetEaseFunction' ) ;
6+ var GetRandomElement = require ( '../../utils/array/GetRandomElement' ) ;
7+ var GetValue = require ( '../../utils/object/GetValue' ) ;
58var MinMax2 = require ( '../../math/MinMax2' ) ;
69var MinMax4 = require ( '../../math/MinMax4' ) ;
710var Particle = require ( './Particle' ) ;
811var StableSort = require ( '../../utils/array/StableSort' ) ;
9- var GetRandomElement = require ( '../../utils/array/GetRandomElement' ) ;
1012
1113var ParticleEmitter = new Class ( {
1214
@@ -24,74 +26,83 @@ var ParticleEmitter = new Class({
2426
2527 this . manager = manager ;
2628
27- this . key = '' ;
29+ this . key = GetValue ( config , 'key' , '' ) ;
2830
29- this . particleClass = Particle ;
31+ this . particleClass = GetValue ( config , 'particleClass' , Particle ) ;
3032
3133 this . texture = manager . texture ;
3234
33- // Unless overriden by the config
34- this . defaultFrame = manager . defaultFrame ;
35-
3635 this . frames = [ manager . defaultFrame ] ;
3736
38- this . dead = [ ] ;
39- this . alive = [ ] ;
37+ this . defaultFrame = manager . defaultFrame ;
4038
41- this . x = 0 ;
42- this . y = 0 ;
39+ this . x = GetValue ( config , 'x' , 0 ) ;
40+ this . y = GetValue ( config , 'y' , 0 ) ;
4341
4442 // A radial emitter will emit particles in all directions between angle min and max
4543 // A point emitter will emit particles only in the direction set by the speed values
46- this . radial = true ;
44+ this . radial = GetValue ( config , 'radial' , true ) ;
4745
48- this . speed = new MinMax4 ( ) ;
46+ this . speed = new MinMax4 ( GetValue ( config , 'speed' , undefined ) ) ;
4947
50- this . scale = new MinMax4 ( 1 ) ;
48+ this . scale = new MinMax4 ( GetValue ( config , 'scale' , 1 ) ) ;
5149
52- this . gravity = new MinMax2 ( ) ;
50+ this . gravity = new MinMax2 ( GetValue ( config , 'gravity' , 0 ) ) ;
5351
54- this . alpha = new MinMax2 ( 1 ) ;
52+ this . alpha = new MinMax2 ( GetValue ( config , 'alpha' , 1 ) ) ;
5553
56- this . angle = new MinMax2 ( 0 , 360 ) ;
54+ this . angle = new MinMax2 ( GetValue ( config , 'angle' , { min : 0 , max : 360 } ) ) ;
5755
58- this . particleAngle = new MinMax2 ( ) ;
56+ this . particleAngle = new MinMax2 ( GetValue ( config , 'particleAngle' , 0 ) ) ;
5957
6058 // The lifespan of the particles (in ms)
61- this . lifespan = new MinMax2 ( 1000 ) ;
59+ this . lifespan = new MinMax2 ( GetValue ( config , 'lifespan' , 1000 ) ) ;
6260
63- this . deathCallback = null ;
64- this . deathCallbackScope = null ;
61+ this . deathCallback = GetValue ( config , 'deathCallback' , null ) ;
62+ this . deathCallbackScope = GetValue ( config , 'deathCallbackScope' , null ) ;
6563
6664 // Set to hard limit the amount of particle objects this emitter is allowed to create
67- this . maxParticles = 0 ;
65+ this . maxParticles = GetValue ( config , 'maxParticles' , 0 ) ;
6866
6967 // How many particles are emitted each time the emitter updates
70- this . emitCount = 1 ;
68+ this . quantity = GetValue ( config , 'quantity' , 1 ) ;
7169
7270 // How often a particle is emitted in ms (if emitter is a constant / flow emitter)
7371 // If emitter is an explosion emitter this value will be -1.
7472 // Anything > -1 sets this to be a flow emitter
75- this . frequency = 0 ;
73+ this . frequency = GetValue ( config , 'frequency' , 0 ) ;
7674
7775 // Controls if the emitter is currently emitting particles. Already alive particles will continue to update until they expire.
78- this . on = true ;
76+ this . on = GetValue ( config , 'on' , true ) ;
7977
8078 // Newly emitted particles are added to the top of the particle list, i.e. rendered above those already alive. Set to false to send them to the back.
81- this . particleBringToTop = true ;
79+ this . particleBringToTop = GetValue ( config , 'particleBringToTop' , true ) ;
8280
83- this . timeScale = 1 ;
81+ this . timeScale = GetValue ( config , 'timeScale' , 1 ) ;
82+
83+ this . dead = [ ] ;
84+ this . alive = [ ] ;
8485
8586 this . _counter = 0 ;
8687
8788 // Optional Particle emission zone - must be an object that supports a `getRandomPoint` function, such as a Rectangle, Circle, Path, etc.
88- this . zone = null ;
89+ this . zone = GetValue ( config , 'zone' , null ) ;
8990
90- this . easingFunctionAlpha = Easing . Linear ;
91- this . easingFunctionScale = Easing . Linear ;
92- this . easingFunctionRotation = Easing . Linear ;
91+ this . active = GetValue ( config , 'active' , true ) ;
92+ this . visible = GetValue ( config , 'visible' , true ) ;
9393
94- this . active = true ;
94+ this . blendMode = GetValue ( config , 'blendMode' , BlendModes . NORMAL ) ;
95+
96+ this . easingFunctionAlpha = GetValue ( config , 'alphaEase' , GetEaseFunction ( 'Linear' ) ) ;
97+ this . easingFunctionScale = GetValue ( config , 'scaleEase' , GetEaseFunction ( 'Linear' ) ) ;
98+ this . easingFunctionRotation = GetValue ( config , 'rotationEase' , GetEaseFunction ( 'Linear' ) ) ;
99+
100+ var frame = GetValue ( config , 'frame' , null ) ;
101+
102+ if ( frame )
103+ {
104+ this . setFrame ( frame ) ;
105+ }
95106 } ,
96107
97108 getFrame : function ( )
@@ -216,7 +227,7 @@ var ParticleEmitter = new Class({
216227
217228 setQuantity : function ( quantity )
218229 {
219- this . emitCount = quantity ;
230+ this . quantity = quantity ;
220231
221232 return this ;
222233 } ,
@@ -229,7 +240,7 @@ var ParticleEmitter = new Class({
229240
230241 if ( quantity )
231242 {
232- this . emitCount = quantity ;
243+ this . quantity = quantity ;
233244 }
234245
235246 return this ;
@@ -376,7 +387,7 @@ var ParticleEmitter = new Class({
376387
377388 this . frequency = frequency ;
378389
379- this . emitCount = count ;
390+ this . quantity = count ;
380391
381392 return this . start ( ) ;
382393 } ,
@@ -516,15 +527,15 @@ var ParticleEmitter = new Class({
516527
517528 if ( this . frequency === 0 )
518529 {
519- this . emit ( this . emitCount ) ;
530+ this . emit ( this . quantity ) ;
520531 }
521532 else if ( this . frequency > 0 )
522533 {
523534 this . _counter -= delta ;
524535
525536 if ( this . _counter <= 0 )
526537 {
527- this . emit ( this . emitCount ) ;
538+ this . emit ( this . quantity ) ;
528539
529540 // counter = frequency - remained from previous delta
530541 this . _counter = ( this . frequency - Math . abs ( this . _counter ) ) ;
0 commit comments