@@ -260,9 +260,6 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
260260 //! Array of particles
261261 _particles :null ,
262262
263- //particle pool
264- _particlePool :null ,
265-
266263 // color modulate
267264 // BOOL colorModulate;
268265
@@ -1195,8 +1192,6 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
11951192 this . _startColorVar = new cc . Color4F ( 1 , 1 , 1 , 1 ) ;
11961193 this . _endColor = new cc . Color4F ( 1 , 1 , 1 , 1 ) ;
11971194 this . _endColorVar = new cc . Color4F ( 1 , 1 , 1 , 1 ) ;
1198-
1199- this . _particlePool = [ ] ;
12001195 } ,
12011196
12021197 /**
@@ -1216,7 +1211,6 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
12161211 * @return {cc.ParticleSystem }
12171212 */
12181213 initWithFile :function ( plistFile ) {
1219- //TODO
12201214 this . _plistFile = plistFile ;
12211215 var dict = cc . FileUtils . getInstance ( ) . dictionaryWithContentsOfFileThreadSafe ( this . _plistFile ) ;
12221216
@@ -1410,8 +1404,11 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
14101404 initWithTotalParticles :function ( numberOfParticles ) {
14111405 this . _totalParticles = numberOfParticles ;
14121406
1407+ var i ;
14131408 this . _particles = [ ] ;
1414- this . _particlePool = [ ] ;
1409+ for ( i = 0 ; i < numberOfParticles ; i ++ ) {
1410+ this . _particles [ i ] = new cc . Particle ( ) ;
1411+ }
14151412
14161413 if ( ! this . _particles ) {
14171414 cc . log ( "Particle system: not enough memory" ) ;
@@ -1420,7 +1417,7 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
14201417 this . _allocatedParticles = numberOfParticles ;
14211418
14221419 if ( this . _batchNode )
1423- for ( var i = 0 ; i < this . _totalParticles ; i ++ )
1420+ for ( i = 0 ; i < this . _totalParticles ; i ++ )
14241421 this . _particles [ i ] . atlasIndex = i ;
14251422
14261423 // default, active
@@ -1455,16 +1452,9 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
14551452 } ,
14561453
14571454 destroyParticleSystem :function ( ) {
1458- this . _particlePool = null ;
14591455 this . unscheduleUpdate ( ) ;
14601456 } ,
14611457
1462- _getParticleObject :function ( ) {
1463- if ( this . _particlePool . length > 0 )
1464- return this . _particlePool . pop ( ) ;
1465- return new cc . Particle ( ) ;
1466- } ,
1467-
14681458 /**
14691459 * Add a particle to the emitter
14701460 * @return {Boolean }
@@ -1473,11 +1463,9 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
14731463 if ( this . isFull ( ) )
14741464 return false ;
14751465
1476- var particle = this . _getParticleObject ( ) ;
1466+ var particle = this . _particles [ this . _particleCount ] ;
14771467 this . initParticle ( particle ) ;
1478- this . _particles . push ( particle ) ;
14791468 ++ this . _particleCount ;
1480-
14811469 return true ;
14821470 } ,
14831471
@@ -1496,19 +1484,34 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
14961484 particle . pos . y = this . _sourcePosition . y + this . _posVar . y * cc . RANDOM_MINUS1_1 ( ) ;
14971485
14981486 // Color
1499- var start = new cc . Color4F (
1500- cc . clampf ( this . _startColor . r + this . _startColorVar . r * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 ) ,
1501- cc . clampf ( this . _startColor . g + this . _startColorVar . g * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 ) ,
1502- cc . clampf ( this . _startColor . b + this . _startColorVar . b * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 ) ,
1503- cc . clampf ( this . _startColor . a + this . _startColorVar . a * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 )
1504- ) ;
1505-
1506- var end = new cc . Color4F (
1507- cc . clampf ( this . _endColor . r + this . _endColorVar . r * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 ) ,
1508- cc . clampf ( this . _endColor . g + this . _endColorVar . g * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 ) ,
1509- cc . clampf ( this . _endColor . b + this . _endColorVar . b * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 ) ,
1510- cc . clampf ( this . _endColor . a + this . _endColorVar . a * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 )
1511- ) ;
1487+ var start , end ;
1488+ if ( cc . renderContextType === cc . CANVAS ) {
1489+ start = new cc . Color4F (
1490+ cc . clampf ( this . _startColor . r + this . _startColorVar . r * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 ) ,
1491+ cc . clampf ( this . _startColor . g + this . _startColorVar . g * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 ) ,
1492+ cc . clampf ( this . _startColor . b + this . _startColorVar . b * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 ) ,
1493+ cc . clampf ( this . _startColor . a + this . _startColorVar . a * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 )
1494+ ) ;
1495+ end = new cc . Color4F (
1496+ cc . clampf ( this . _endColor . r + this . _endColorVar . r * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 ) ,
1497+ cc . clampf ( this . _endColor . g + this . _endColorVar . g * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 ) ,
1498+ cc . clampf ( this . _endColor . b + this . _endColorVar . b * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 ) ,
1499+ cc . clampf ( this . _endColor . a + this . _endColorVar . a * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 )
1500+ ) ;
1501+ } else {
1502+ start = {
1503+ r : cc . clampf ( this . _startColor . r + this . _startColorVar . r * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 ) ,
1504+ g : cc . clampf ( this . _startColor . g + this . _startColorVar . g * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 ) ,
1505+ b : cc . clampf ( this . _startColor . b + this . _startColorVar . b * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 ) ,
1506+ a : cc . clampf ( this . _startColor . a + this . _startColorVar . a * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 )
1507+ } ;
1508+ end = {
1509+ r : cc . clampf ( this . _endColor . r + this . _endColorVar . r * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 ) ,
1510+ g : cc . clampf ( this . _endColor . g + this . _endColorVar . g * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 ) ,
1511+ b : cc . clampf ( this . _endColor . b + this . _endColorVar . b * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 ) ,
1512+ a : cc . clampf ( this . _endColor . a + this . _endColorVar . a * cc . RANDOM_MINUS1_1 ( ) , 0 , 1 )
1513+ } ;
1514+ }
15121515
15131516 particle . color = start ;
15141517 particle . deltaColor . r = ( end . r - start . r ) / particle . timeToLive ;
@@ -1521,8 +1524,7 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
15211524 startS = Math . max ( 0 , startS ) ; // No negative value
15221525
15231526 particle . size = startS ;
1524-
1525- if ( this . _endSize == cc . PARTICLE_START_SIZE_EQUAL_TO_END_SIZE ) {
1527+ if ( this . _endSize === cc . PARTICLE_START_SIZE_EQUAL_TO_END_SIZE ) {
15261528 particle . deltaSize = 0 ;
15271529 } else {
15281530 var endS = this . _endSize + this . _endSizeVar * cc . RANDOM_MINUS1_1 ( ) ;
@@ -1546,7 +1548,7 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
15461548 var a = cc . DEGREES_TO_RADIANS ( this . _angle + this . _angleVar * cc . RANDOM_MINUS1_1 ( ) ) ;
15471549
15481550 // Mode Gravity: A
1549- if ( this . _emitterMode == cc . PARTICLE_MODE_GRAVITY ) {
1551+ if ( this . _emitterMode === cc . PARTICLE_MODE_GRAVITY ) {
15501552 var v = cc . p ( Math . cos ( a ) , Math . sin ( a ) ) ;
15511553 var s = this . modeA . speed + this . modeA . speedVar * cc . RANDOM_MINUS1_1 ( ) ;
15521554
@@ -1566,8 +1568,7 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
15661568 var endRadius = this . modeB . endRadius + this . modeB . endRadiusVar * cc . RANDOM_MINUS1_1 ( ) ;
15671569
15681570 particle . modeB . radius = startRadius ;
1569-
1570- if ( this . modeB . endRadius == cc . PARTICLE_START_RADIUS_EQUAL_TO_END_RADIUS ) {
1571+ if ( this . modeB . endRadius === cc . PARTICLE_START_RADIUS_EQUAL_TO_END_RADIUS ) {
15711572 particle . modeB . deltaRadius = 0 ;
15721573 } else {
15731574 particle . modeB . deltaRadius = ( endRadius - startRadius ) / particle . timeToLive ;
@@ -1585,8 +1586,6 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
15851586 this . _isActive = false ;
15861587 this . _elapsed = this . _duration ;
15871588 this . _emitCounter = 0 ;
1588-
1589- this . _particlePool = [ ] ;
15901589 } ,
15911590
15921591 /**
@@ -1595,10 +1594,8 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
15951594 resetSystem :function ( ) {
15961595 this . _isActive = true ;
15971596 this . _elapsed = 0 ;
1598- for ( this . _particleIdx = 0 ; this . _particleIdx < this . _particleCount ; ++ this . _particleIdx ) {
1599- var p = this . _particles [ this . _particleIdx ] ;
1600- p . timeToLive = 0 ;
1601- }
1597+ for ( this . _particleIdx = 0 ; this . _particleIdx < this . _particleCount ; ++ this . _particleIdx )
1598+ this . _particles [ this . _particleIdx ] . timeToLive = 0 ;
16021599 } ,
16031600
16041601 /**
@@ -1690,13 +1687,13 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
16901687 selParticle . pos = cc . pAdd ( selParticle . pos , tmp ) ;
16911688 } else {
16921689 // Mode B: radius movement
1693-
1690+ var selModeB = selParticle . modeB ;
16941691 // Update the angle and radius of the particle.
1695- selParticle . modeB . angle += selParticle . modeB . degreesPerSecond * dt ;
1696- selParticle . modeB . radius += selParticle . modeB . deltaRadius * dt ;
1692+ selModeB . angle += selModeB . degreesPerSecond * dt ;
1693+ selModeB . radius += selModeB . deltaRadius * dt ;
16971694
1698- selParticle . pos . x = - Math . cos ( selParticle . modeB . angle ) * selParticle . modeB . radius ;
1699- selParticle . pos . y = - Math . sin ( selParticle . modeB . angle ) * selParticle . modeB . radius ;
1695+ selParticle . pos . x = - Math . cos ( selModeB . angle ) * selModeB . radius ;
1696+ selParticle . pos . y = - Math . sin ( selModeB . angle ) * selModeB . radius ;
17001697 }
17011698
17021699 // color
@@ -1745,11 +1742,11 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
17451742 } else {
17461743 // life < 0
17471744 var currentIndex = selParticle . atlasIndex ;
1748- cc . ArrayRemoveObject ( this . _particles , selParticle ) ;
1749-
1750- //cache particle to pool
1751- this . _particlePool . push ( selParticle ) ;
1752-
1745+ if ( this . _particleIdx !== this . _particleCount - 1 ) {
1746+ var deadParticle = this . _particles [ this . _particleIdx ] ;
1747+ this . _particles [ this . _particleIdx ] = this . _particles [ this . _particleCount - 1 ] ;
1748+ this . _particles [ this . _particleCount - 1 ] = deadParticle ;
1749+ }
17531750 if ( this . _batchNode ) {
17541751 //disable the switched particle
17551752 this . _batchNode . disableParticle ( this . _atlasIndex + currentIndex ) ;
0 commit comments