1 /****************************************************************************
  2  Copyright (c) 2010-2012 cocos2d-x.org
  3  Copyright (c) 2008-2010 Ricardo Quesada
  4  Copyright (c) 2011      Zynga Inc.
  5 
  6  http://www.cocos2d-x.org
  7 
  8  Permission is hereby granted, free of charge, to any person obtaining a copy
  9  of this software and associated documentation files (the "Software"), to deal
 10  in the Software without restriction, including without limitation the rights
 11  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 12  copies of the Software, and to permit persons to whom the Software is
 13  furnished to do so, subject to the following conditions:
 14 
 15  The above copyright notice and this permission notice shall be included in
 16  all copies or substantial portions of the Software.
 17 
 18  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 19  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 20  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 21  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 22  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 23  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 24  THE SOFTWARE.
 25  ****************************************************************************/
 26 
 27 /**
 28  * A fire particle system
 29  * @class
 30  * @extends cc.ParticleSystem
 31  *
 32  * @example
 33  * var emitter = cc.ParticleFire.create();
 34  */
 35 cc.ParticleFire = cc.ParticleSystem.extend(/** @lends cc.ParticleFire# */{
 36     /**
 37      * initialize a fire particle system
 38      * @return {Boolean}
 39      */
 40     init:function () {
 41         return this.initWithTotalParticles((cc.renderContextType === cc.WEBGL) ? 300 : 150);
 42     },
 43 
 44     /**
 45      * initialize a fire particle system with number Of Particles
 46      * @param {Number} numberOfParticles
 47      * @return {Boolean}
 48      */
 49     initWithTotalParticles:function (numberOfParticles) {
 50         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
 51             // duration
 52             this._duration = cc.PARTICLE_DURATION_INFINITY;
 53 
 54             // Gravity Mode
 55             this._emitterMode = cc.PARTICLE_MODE_GRAVITY;
 56 
 57             // Gravity Mode: gravity
 58             this.modeA.gravity = cc.p(0, 0);
 59 
 60             // Gravity Mode: radial acceleration
 61             this.modeA.radialAccel = 0;
 62             this.modeA.radialAccelVar = 0;
 63 
 64             // Gravity Mode: speed of particles
 65             this.modeA.speed = 60;
 66             this.modeA.speedVar = 20;
 67 
 68             // starting angle
 69             this._angle = 90;
 70             this._angleVar = 10;
 71 
 72             // emitter position
 73             var winSize = cc.Director.getInstance().getWinSize();
 74             this.setPosition(winSize.width / 2, 60);
 75             this._posVar = cc.p(40, 20);
 76 
 77             // life of particles
 78             this._life = 3;
 79             this._lifeVar = 0.25;
 80 
 81 
 82             // size, in pixels
 83             this._startSize = 54.0;
 84             this._startSizeVar = 10.0;
 85             this._endSize = cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE;
 86 
 87             // emits per frame
 88             this._emissionRate = this._totalParticles / this._life;
 89 
 90             // color of particles
 91             this._startColor.r = 0.76;
 92             this._startColor.g = 0.25;
 93             this._startColor.b = 0.12;
 94             this._startColor.a = 1.0;
 95             this._startColorVar.r = 0.0;
 96             this._startColorVar.g = 0.0;
 97             this._startColorVar.b = 0.0;
 98             this._startColorVar.a = 0.0;
 99             this._endColor.r = 0.0;
100             this._endColor.g = 0.0;
101             this._endColor.b = 0.0;
102             this._endColor.a = 1.0;
103             this._endColorVar.r = 0.0;
104             this._endColorVar.g = 0.0;
105             this._endColorVar.b = 0.0;
106             this._endColorVar.a = 0.0;
107 
108             // additive
109             this.setBlendAdditive(true);
110             return true;
111         }
112         return false;
113     }
114 });
115 
116 /**
117  * Create a fire particle system
118  * @return {cc.ParticleFire}
119  *
120  * @example
121  * var emitter = cc.ParticleFire.create();
122  */
123 cc.ParticleFire.create = function () {
124     var ret = new cc.ParticleFire();
125     if (ret.init()) {
126         return ret;
127     }
128     return null;
129 };
130 
131 /**
132  * A fireworks particle system
133  * @class
134  * @extends cc.ParticleSystem
135  *
136  * @example
137  * var emitter = cc.ParticleFireworks.create();
138  */
139 cc.ParticleFireworks = cc.ParticleSystem.extend(/** @lends cc.ParticleFireworks# */{
140     /**
141      * initialize a fireworks particle system
142      * @return {Boolean}
143      */
144     init:function () {
145         return this.initWithTotalParticles((cc.renderContextType === cc.WEBGL) ? 1500 : 150);
146     },
147 
148     /**
149      * initialize a fireworks particle system with number Of Particles
150      * @param {Number} numberOfParticles
151      * @return {Boolean}
152      */
153     initWithTotalParticles:function (numberOfParticles) {
154         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
155             // duration
156             this._duration = cc.PARTICLE_DURATION_INFINITY;
157 
158             // Gravity Mode
159             this._emitterMode = cc.PARTICLE_MODE_GRAVITY;
160 
161             // Gravity Mode: gravity
162             this.modeA.gravity = cc.p(0, -90);
163 
164             // Gravity Mode:  radial
165             this.modeA.radialAccel = 0;
166             this.modeA.radialAccelVar = 0;
167 
168             //  Gravity Mode: speed of particles
169             this.modeA.speed = 180;
170             this.modeA.speedVar = 50;
171 
172             // emitter position
173             var winSize = cc.Director.getInstance().getWinSize();
174             this.setPosition(winSize.width / 2, winSize.height / 2);
175 
176             // angle
177             this._angle = 90;
178             this._angleVar = 20;
179 
180             // life of particles
181             this._life = 3.5;
182             this._lifeVar = 1;
183 
184             // emits per frame
185             this._emissionRate = this._totalParticles / this._life;
186 
187             // color of particles
188             this._startColor.r = 0.5;
189             this._startColor.g = 0.5;
190             this._startColor.b = 0.5;
191             this._startColor.a = 1.0;
192             this._startColorVar.r = 0.5;
193             this._startColorVar.g = 0.5;
194             this._startColorVar.b = 0.5;
195             this._startColorVar.a = 0.1;
196             this._endColor.r = 0.1;
197             this._endColor.g = 0.1;
198             this._endColor.b = 0.1;
199             this._endColor.a = 0.2;
200             this._endColorVar.r = 0.1;
201             this._endColorVar.g = 0.1;
202             this._endColorVar.b = 0.1;
203             this._endColorVar.a = 0.2;
204 
205             // size, in pixels
206             this._startSize = 8.0;
207             this._startSizeVar = 2.0;
208             this._endSize = cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE;
209 
210             // additive
211             this.setBlendAdditive(false);
212             return true;
213         }
214         return false;
215     }
216 });
217 
218 /**
219  * Create a fireworks particle system
220  * @return {cc.ParticleFireworks}
221  *
222  * @example
223  * var emitter = cc.ParticleFireworks.create();
224  */
225 cc.ParticleFireworks.create = function () {
226     var ret = new cc.ParticleFireworks();
227     if (ret.init()) {
228         return ret;
229     }
230     return null;
231 };
232 
233 /**
234  * A sun particle system
235  * @class
236  * @extends cc.ParticleSystem
237  *
238  * @example
239  * var emitter = cc.ParticleSun.create();
240  */
241 cc.ParticleSun = cc.ParticleSystem.extend(/** @lends cc.ParticleSun# */{
242     /**
243      * initialize a sun particle system
244      * @return {Boolean}
245      */
246     init:function () {
247         return this.initWithTotalParticles((cc.renderContextType === cc.WEBGL) ? 350 : 150);
248     },
249 
250     /**
251      * initialize a sun particle system with number Of Particles
252      * @param {Number} numberOfParticles
253      * @return {Boolean}
254      */
255     initWithTotalParticles:function (numberOfParticles) {
256         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
257             // additive
258             this.setBlendAdditive(true);
259 
260             // duration
261             this._duration = cc.PARTICLE_DURATION_INFINITY;
262 
263             // Gravity Mode
264             this.setEmitterMode(cc.PARTICLE_MODE_GRAVITY);
265 
266             // Gravity Mode: gravity
267             this.setGravity(cc.p(0, 0));
268 
269             // Gravity mode: radial acceleration
270             this.setRadialAccel(0);
271             this.setRadialAccelVar(0);
272 
273             // Gravity mode: speed of particles
274             this.setSpeed(20);
275             this.setSpeedVar(5);
276 
277             // angle
278             this._angle = 90;
279             this._angleVar = 360;
280 
281             // emitter position
282             var winSize = cc.Director.getInstance().getWinSize();
283             this.setPosition(winSize.width / 2, winSize.height / 2);
284             this.setPosVar(cc.PointZero());
285 
286             // life of particles
287             this._life = 1;
288             this._lifeVar = 0.5;
289 
290             // size, in pixels
291             this._startSize = 30.0;
292             this._startSizeVar = 10.0;
293             this._endSize = cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE;
294 
295             // emits per seconds
296             this._emissionRate = this._totalParticles / this._life;
297 
298             // color of particles
299             this._startColor.r = 0.76;
300             this._startColor.g = 0.25;
301             this._startColor.b = 0.12;
302             this._startColor.a = 1.0;
303             this._startColorVar.r = 0.0;
304             this._startColorVar.g = 0.0;
305             this._startColorVar.b = 0.0;
306             this._startColorVar.a = 0.0;
307             this._endColor.r = 0.0;
308             this._endColor.g = 0.0;
309             this._endColor.b = 0.0;
310             this._endColor.a = 1.0;
311             this._endColorVar.r = 0.0;
312             this._endColorVar.g = 0.0;
313             this._endColorVar.b = 0.0;
314             this._endColorVar.a = 0.0;
315 
316             return true;
317         }
318         return false;
319     }
320 });
321 
322 /**
323  * Create a sun particle system
324  * @return {cc.ParticleSun}
325  *
326  * @example
327  * var emitter = cc.ParticleSun.create();
328  */
329 cc.ParticleSun.create = function () {
330     var ret = new cc.ParticleSun();
331     if (ret.init()) {
332         return ret;
333     }
334     return null;
335 };
336 
337 //! @brief A  particle system
338 /**
339  * A galaxy particle system
340  * @class
341  * @extends cc.ParticleSystem
342  *
343  * @example
344  * var emitter = cc.ParticleGalaxy.create();
345  */
346 cc.ParticleGalaxy = cc.ParticleSystem.extend(/** @lends cc.ParticleGalaxy# */{
347     /**
348      * initialize a galaxy particle system
349      * @return {Boolean}
350      */
351     init:function () {
352         //return this.initWithTotalParticles(200);
353         return this.initWithTotalParticles((cc.renderContextType === cc.WEBGL) ? 200 : 100);
354     },
355 
356     /**
357      * initialize a galaxy particle system with number Of Particles
358      * @param {Number} numberOfParticles
359      * @return {Boolean}
360      */
361     initWithTotalParticles:function (numberOfParticles) {
362         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
363             // duration
364             this._duration = cc.PARTICLE_DURATION_INFINITY;
365 
366             // Gravity Mode
367             this._emitterMode = cc.PARTICLE_MODE_GRAVITY;
368 
369             // Gravity Mode: gravity
370             this.modeA.gravity = cc.p(0, 0);
371 
372             // Gravity Mode: speed of particles
373             this.modeA.speed = 60;
374             this.modeA.speedVar = 10;
375 
376             // Gravity Mode: radial
377             this.modeA.radialAccel = -80;
378             this.modeA.radialAccelVar = 0;
379 
380             // Gravity Mode: tagential
381             this.modeA.tangentialAccel = 80;
382             this.modeA.tangentialAccelVar = 0;
383 
384             // angle
385             this._angle = 90;
386             this._angleVar = 360;
387 
388             // emitter position
389             var winSize = cc.Director.getInstance().getWinSize();
390             this.setPosition(winSize.width / 2, winSize.height / 2);
391             this._posVar = cc.PointZero();
392 
393             // life of particles
394             this._life = 4;
395             this._lifeVar = 1;
396 
397             // size, in pixels
398             this._startSize = 37.0;
399             this._startSizeVar = 10.0;
400             this._endSize = cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE;
401 
402             // emits per second
403             this._emissionRate = this._totalParticles / this._life;
404 
405             // color of particles
406             this._startColor.r = 0.12;
407             this._startColor.g = 0.25;
408             this._startColor.b = 0.76;
409             this._startColor.a = 1.0;
410             this._startColorVar.r = 0.0;
411             this._startColorVar.g = 0.0;
412             this._startColorVar.b = 0.0;
413             this._startColorVar.a = 0.0;
414             this._endColor.r = 0.0;
415             this._endColor.g = 0.0;
416             this._endColor.b = 0.0;
417             this._endColor.a = 1.0;
418             this._endColorVar.r = 0.0;
419             this._endColorVar.g = 0.0;
420             this._endColorVar.b = 0.0;
421             this._endColorVar.a = 0.0;
422 
423             // additive
424             this.setBlendAdditive(true);
425             return true;
426         }
427         return false;
428     }
429 });
430 /**
431  * Create a galaxy particle system
432  * @return {cc.ParticleGalaxy}
433  *
434  * @example
435  * var emitter = cc.ParticleGalaxy.create();
436  */
437 cc.ParticleGalaxy.create = function () {
438     var ret = new cc.ParticleGalaxy();
439     if (ret.init()) {
440         return ret;
441     }
442     return null;
443 };
444 
445 /**
446  * A flower particle system
447  * @class
448  * @extends cc.ParticleSystem
449  *
450  * @example
451  * var emitter = cc.ParticleFlower.create();
452  */
453 cc.ParticleFlower = cc.ParticleSystem.extend(/** @lends cc.ParticleFlower# */{
454     /**
455      * initialize a flower particle system
456      * @return {Boolean}
457      */
458     init:function () {
459         return this.initWithTotalParticles((cc.renderContextType === cc.WEBGL) ? 250 : 100);
460     },
461 
462     /**
463      * initialize a flower particle system with number Of Particles
464      * @param {Number} numberOfParticles
465      * @return {Boolean}
466      */
467     initWithTotalParticles:function (numberOfParticles) {
468         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
469             // duration
470             this._duration = cc.PARTICLE_DURATION_INFINITY;
471 
472             // Gravity Mode
473             this._emitterMode = cc.PARTICLE_MODE_GRAVITY;
474 
475             // Gravity Mode: gravity
476             this.modeA.gravity = cc.p(0, 0);
477 
478             // Gravity Mode: speed of particles
479             this.modeA.speed = 80;
480             this.modeA.speedVar = 10;
481 
482             // Gravity Mode: radial
483             this.modeA.radialAccel = -60;
484             this.modeA.radialAccelVar = 0;
485 
486             // Gravity Mode: tagential
487             this.modeA.tangentialAccel = 15;
488             this.modeA.tangentialAccelVar = 0;
489 
490             // angle
491             this._angle = 90;
492             this._angleVar = 360;
493 
494             // emitter position
495             var winSize = cc.Director.getInstance().getWinSize();
496             this.setPosition(winSize.width / 2, winSize.height / 2);
497             this._posVar = cc.PointZero();
498 
499             // life of particles
500             this._life = 4;
501             this._lifeVar = 1;
502 
503             // size, in pixels
504             this._startSize = 30.0;
505             this._startSizeVar = 10.0;
506             this._endSize = cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE;
507 
508             // emits per second
509             this._emissionRate = this._totalParticles / this._life;
510 
511             // color of particles
512             this._startColor.r = 0.50;
513             this._startColor.g = 0.50;
514             this._startColor.b = 0.50;
515             this._startColor.a = 1.0;
516             this._startColorVar.r = 0.5;
517             this._startColorVar.g = 0.5;
518             this._startColorVar.b = 0.5;
519             this._startColorVar.a = 0.5;
520             this._endColor.r = 0.0;
521             this._endColor.g = 0.0;
522             this._endColor.b = 0.0;
523             this._endColor.a = 1.0;
524             this._endColorVar.r = 0.0;
525             this._endColorVar.g = 0.0;
526             this._endColorVar.b = 0.0;
527             this._endColorVar.a = 0.0;
528 
529             // additive
530             this.setBlendAdditive(true);
531             return true;
532         }
533         return false;
534     }
535 });
536 
537 /**
538  * Create a flower particle system
539  * @return {cc.ParticleFlower}
540  *
541  * @example
542  * var emitter = cc.ParticleFlower.create();
543  */
544 cc.ParticleFlower.create = function () {
545     var ret = new cc.ParticleFlower();
546     if (ret.init()) {
547         return ret;
548     }
549     return null;
550 };
551 
552 //! @brief A meteor particle system
553 /**
554  * A meteor particle system
555  * @class
556  * @extends cc.ParticleSystem
557  *
558  * @example
559  * var emitter = cc.ParticleMeteor.create();
560  */
561 cc.ParticleMeteor = cc.ParticleSystem.extend(/** @lends cc.ParticleMeteor# */{
562     /**
563      * initialize a meteor particle system
564      * @return {Boolean}
565      */
566     init:function () {
567         return this.initWithTotalParticles((cc.renderContextType === cc.WEBGL) ? 150 : 100);
568     },
569 
570     /**
571      * initialize a meteor particle system with number Of Particles
572      * @param {Number} numberOfParticles
573      * @return {Boolean}
574      */
575     initWithTotalParticles:function (numberOfParticles) {
576         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
577             // duration
578             this._duration = cc.PARTICLE_DURATION_INFINITY;
579 
580             // Gravity Mode
581             this._emitterMode = cc.PARTICLE_MODE_GRAVITY;
582 
583             // Gravity Mode: gravity
584             this.modeA.gravity = cc.p(-200, 200);
585 
586             // Gravity Mode: speed of particles
587             this.modeA.speed = 15;
588             this.modeA.speedVar = 5;
589 
590             // Gravity Mode: radial
591             this.modeA.radialAccel = 0;
592             this.modeA.radialAccelVar = 0;
593 
594             // Gravity Mode: tagential
595             this.modeA.tangentialAccel = 0;
596             this.modeA.tangentialAccelVar = 0;
597 
598             // angle
599             this._angle = 90;
600             this._angleVar = 360;
601 
602             // emitter position
603             var winSize = cc.Director.getInstance().getWinSize();
604             this.setPosition(winSize.width / 2, winSize.height / 2);
605             this._posVar = cc.PointZero();
606 
607             // life of particles
608             this._life = 2;
609             this._lifeVar = 1;
610 
611             // size, in pixels
612             this._startSize = 60.0;
613             this._startSizeVar = 10.0;
614             this._endSize = cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE;
615 
616             // emits per second
617             this._emissionRate = this._totalParticles / this._life;
618 
619             // color of particles
620             this._startColor.r = 0.2;
621             this._startColor.g = 0.4;
622             this._startColor.b = 0.7;
623             this._startColor.a = 1.0;
624             this._startColorVar.r = 0.0;
625             this._startColorVar.g = 0.0;
626             this._startColorVar.b = 0.2;
627             this._startColorVar.a = 0.1;
628             this._endColor.r = 0.0;
629             this._endColor.g = 0.0;
630             this._endColor.b = 0.0;
631             this._endColor.a = 1.0;
632             this._endColorVar.r = 0.0;
633             this._endColorVar.g = 0.0;
634             this._endColorVar.b = 0.0;
635             this._endColorVar.a = 0.0;
636 
637             // additive
638             this.setBlendAdditive(true);
639             return true;
640         }
641         return false;
642     }
643 });
644 
645 /**
646  * Create a meteor particle system
647  * @return {cc.ParticleFireworks}
648  *
649  * @example
650  * var emitter = cc.ParticleMeteor.create();
651  */
652 cc.ParticleMeteor.create = function () {
653     var ret = new cc.ParticleMeteor();
654     if (ret.init()) {
655         return ret;
656     }
657     return null;
658 };
659 
660 /**
661  * A spiral particle system
662  * @class
663  * @extends cc.ParticleSystem
664  *
665  * @example
666  * var emitter = cc.ParticleSpiral.create();
667  */
668 cc.ParticleSpiral = cc.ParticleSystem.extend(/** @lends cc.ParticleSpiral# */{
669     /**
670      * initialize a spiral particle system
671      * @return {Boolean}
672      */
673     init:function () {
674         return this.initWithTotalParticles((cc.renderContextType === cc.WEBGL) ? 500 : 100);
675     },
676 
677     /**
678      * initialize a spiral particle system with number Of Particles
679      * @param {Number} numberOfParticles
680      * @return {Boolean}
681      */
682     initWithTotalParticles:function (numberOfParticles) {
683         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
684             // duration
685             this._duration = cc.PARTICLE_DURATION_INFINITY;
686 
687             // Gravity Mode
688             this._emitterMode = cc.PARTICLE_MODE_GRAVITY;
689 
690             // Gravity Mode: gravity
691             this.modeA.gravity = cc.p(0, 0);
692 
693             // Gravity Mode: speed of particles
694             this.modeA.speed = 150;
695             this.modeA.speedVar = 0;
696 
697             // Gravity Mode: radial
698             this.modeA.radialAccel = -380;
699             this.modeA.radialAccelVar = 0;
700 
701             // Gravity Mode: tagential
702             this.modeA.tangentialAccel = 45;
703             this.modeA.tangentialAccelVar = 0;
704 
705             // angle
706             this._angle = 90;
707             this._angleVar = 0;
708 
709             // emitter position
710             var winSize = cc.Director.getInstance().getWinSize();
711             this.setPosition(winSize.width / 2, winSize.height / 2);
712             this._posVar = cc.PointZero();
713 
714             // life of particles
715             this._life = 12;
716             this._lifeVar = 0;
717 
718             // size, in pixels
719             this._startSize = 20.0;
720             this._startSizeVar = 0.0;
721             this._endSize = cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE;
722 
723             // emits per second
724             this._emissionRate = this._totalParticles / this._life;
725 
726             // color of particles
727             this._startColor.r = 0.5;
728             this._startColor.g = 0.5;
729             this._startColor.b = 0.5;
730             this._startColor.a = 1.0;
731             this._startColorVar.r = 0.5;
732             this._startColorVar.g = 0.5;
733             this._startColorVar.b = 0.5;
734             this._startColorVar.a = 0.0;
735             this._endColor.r = 0.5;
736             this._endColor.g = 0.5;
737             this._endColor.b = 0.5;
738             this._endColor.a = 1.0;
739             this._endColorVar.r = 0.5;
740             this._endColorVar.g = 0.5;
741             this._endColorVar.b = 0.5;
742             this._endColorVar.a = 0.0;
743 
744             // additive
745             this.setBlendAdditive(false);
746             return true;
747         }
748         return false;
749     }
750 });
751 
752 /**
753  * Create a spiral particle system
754  * @return {cc.ParticleSpiral}
755  *
756  * @example
757  * var emitter = cc.ParticleSpiral.create();
758  */
759 cc.ParticleSpiral.create = function () {
760     var ret = new cc.ParticleSpiral();
761     if (ret.init()) {
762         return ret;
763     }
764     return null;
765 };
766 
767 /**
768  * An explosion particle system
769  * @class
770  * @extends cc.ParticleSystem
771  *
772  * @example
773  * var emitter = cc.ParticleExplosion.create();
774  */
775 cc.ParticleExplosion = cc.ParticleSystem.extend(/** @lends cc.ParticleExplosion# */{
776     /**
777      * initialize an explosion particle system
778      * @return {Boolean}
779      */
780     init:function () {
781         //return this.initWithTotalParticles(700);
782         return this.initWithTotalParticles((cc.renderContextType === cc.WEBGL) ? 700 : 300);
783     },
784 
785     /**
786      * initialize an explosion particle system with number Of Particles
787      * @param {Number} numberOfParticles
788      * @return {Boolean}
789      */
790     initWithTotalParticles:function (numberOfParticles) {
791         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
792             // duration
793             this._duration = 0.1;
794 
795             this._emitterMode = cc.PARTICLE_MODE_GRAVITY;
796 
797             // Gravity Mode: gravity
798             this.modeA.gravity = cc.p(0, 0);
799 
800             // Gravity Mode: speed of particles
801             this.modeA.speed = 70;
802             this.modeA.speedVar = 40;
803 
804             // Gravity Mode: radial
805             this.modeA.radialAccel = 0;
806             this.modeA.radialAccelVar = 0;
807 
808             // Gravity Mode: tagential
809             this.modeA.tangentialAccel = 0;
810             this.modeA.tangentialAccelVar = 0;
811 
812             // angle
813             this._angle = 90;
814             this._angleVar = 360;
815 
816             // emitter position
817             var winSize = cc.Director.getInstance().getWinSize();
818             this.setPosition(winSize.width / 2, winSize.height / 2);
819             this._posVar = cc.PointZero();
820 
821             // life of particles
822             this._life = 5.0;
823             this._lifeVar = 2;
824 
825             // size, in pixels
826             this._startSize = 15.0;
827             this._startSizeVar = 10.0;
828             this._endSize = cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE;
829 
830             // emits per second
831             this._emissionRate = this._totalParticles / this._duration;
832 
833             // color of particles
834             this._startColor.r = 0.7;
835             this._startColor.g = 0.1;
836             this._startColor.b = 0.2;
837             this._startColor.a = 1.0;
838             this._startColorVar.r = 0.5;
839             this._startColorVar.g = 0.5;
840             this._startColorVar.b = 0.5;
841             this._startColorVar.a = 0.0;
842             this._endColor.r = 0.5;
843             this._endColor.g = 0.5;
844             this._endColor.b = 0.5;
845             this._endColor.a = 0.0;
846             this._endColorVar.r = 0.5;
847             this._endColorVar.g = 0.5;
848             this._endColorVar.b = 0.5;
849             this._endColorVar.a = 0.0;
850 
851             // additive
852             this.setBlendAdditive(false);
853             return true;
854         }
855         return false;
856     }
857 });
858 
859 /**
860  * Create an explosion particle system
861  * @return {cc.ParticleExplosion}
862  *
863  * @example
864  * var emitter = cc.ParticleExplosion.create();
865  */
866 cc.ParticleExplosion.create = function () {
867     var ret = new cc.ParticleExplosion();
868     if (ret.init()) {
869         return ret;
870     }
871     return null;
872 };
873 
874 /**
875  * A smoke particle system
876  * @class
877  * @extends cc.ParticleSystem
878  *
879  * @example
880  * var emitter = cc.ParticleSmoke.create();
881  */
882 cc.ParticleSmoke = cc.ParticleSystem.extend(/** @lends cc.ParticleSmoke# */{
883     /**
884      * initialize a smoke particle system
885      * @return {Boolean}
886      */
887     init:function () {
888         //return this.initWithTotalParticles(200);
889         return this.initWithTotalParticles((cc.renderContextType === cc.WEBGL) ? 200 : 100);
890     },
891 
892     /**
893      * initialize a smoke particle system with number Of Particles
894      * @param {Number} numberOfParticles
895      * @return {Boolean}
896      */
897     initWithTotalParticles:function (numberOfParticles) {
898         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
899             // duration
900             this._duration = cc.PARTICLE_DURATION_INFINITY;
901 
902             // Emitter mode: Gravity Mode
903             this._emitterMode = cc.PARTICLE_MODE_GRAVITY;
904 
905             // Gravity Mode: gravity
906             this.modeA.gravity = cc.p(0, 0);
907 
908             // Gravity Mode: radial acceleration
909             this.modeA.radialAccel = 0;
910             this.modeA.radialAccelVar = 0;
911 
912             // Gravity Mode: speed of particles
913             this.modeA.speed = 25;
914             this.modeA.speedVar = 10;
915 
916             // angle
917             this._angle = 90;
918             this._angleVar = 5;
919 
920             // emitter position
921             var winSize = cc.Director.getInstance().getWinSize();
922             this.setPosition(winSize.width / 2, 0);
923             this._posVar = cc.p(20, 0);
924 
925             // life of particles
926             this._life = 4;
927             this._lifeVar = 1;
928 
929             // size, in pixels
930             this._startSize = 60.0;
931             this._startSizeVar = 10.0;
932             this._endSize = cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE;
933 
934             // emits per frame
935             this._emissionRate = this._totalParticles / this._life;
936 
937             // color of particles
938             this._startColor.r = 0.8;
939             this._startColor.g = 0.8;
940             this._startColor.b = 0.8;
941             this._startColor.a = 1.0;
942             this._startColorVar.r = 0.02;
943             this._startColorVar.g = 0.02;
944             this._startColorVar.b = 0.02;
945             this._startColorVar.a = 0.0;
946             this._endColor.r = 0.0;
947             this._endColor.g = 0.0;
948             this._endColor.b = 0.0;
949             this._endColor.a = 1.0;
950             this._endColorVar.r = 0.0;
951             this._endColorVar.g = 0.0;
952             this._endColorVar.b = 0.0;
953             this._endColorVar.a = 0.0;
954 
955             // additive
956             this.setBlendAdditive(false);
957             return true;
958         }
959         return false;
960     }
961 });
962 
963 /**
964  * Create a smoke particle system
965  * @return {cc.ParticleFireworks}
966  *
967  * @example
968  * var emitter = cc.ParticleFireworks.create();
969  */
970 cc.ParticleSmoke.create = function () {
971     var ret = new cc.ParticleSmoke();
972     if (ret.init()) {
973         return ret;
974     }
975     return null;
976 };
977 
978 /**
979  * A snow particle system
980  * @class
981  * @extends cc.ParticleSystem
982  *
983  * @example
984  * var emitter = cc.ParticleSnow.create();
985  */
986 cc.ParticleSnow = cc.ParticleSystem.extend(/** @lends cc.ParticleSnow# */{
987     /**
988      * initialize a snow particle system
989      * @return {Boolean}
990      */
991     init:function () {
992         return this.initWithTotalParticles((cc.renderContextType === cc.WEBGL) ? 700 : 250);
993     },
994 
995     /**
996      * initialize a snow particle system with number Of Particles
997      * @param {Number} numberOfParticles
998      * @return {Boolean}
999      */
1000     initWithTotalParticles:function (numberOfParticles) {
1001         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
1002             // duration
1003             this._duration = cc.PARTICLE_DURATION_INFINITY;
1004 
1005             // set gravity mode.
1006             this._emitterMode = cc.PARTICLE_MODE_GRAVITY;
1007 
1008             // Gravity Mode: gravity
1009             this.modeA.gravity = cc.p(0, -1);
1010 
1011             // Gravity Mode: speed of particles
1012             this.modeA.speed = 5;
1013             this.modeA.speedVar = 1;
1014 
1015             // Gravity Mode: radial
1016             this.modeA.radialAccel = 0;
1017             this.modeA.radialAccelVar = 1;
1018 
1019             // Gravity mode: tagential
1020             this.modeA.tangentialAccel = 0;
1021             this.modeA.tangentialAccelVar = 1;
1022 
1023             // emitter position
1024             var winSize = cc.Director.getInstance().getWinSize();
1025             this.setPosition(winSize.width / 2, winSize.height + 10);
1026             this._posVar = cc.p(winSize.width / 2, 0);
1027 
1028             // angle
1029             this._angle = -90;
1030             this._angleVar = 5;
1031 
1032             // life of particles
1033             this._life = 45;
1034             this._lifeVar = 15;
1035 
1036             // size, in pixels
1037             this._startSize = 10.0;
1038             this._startSizeVar = 5.0;
1039             this._endSize = cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE;
1040 
1041             // emits per second
1042             this._emissionRate = 10;
1043 
1044             // color of particles
1045             this._startColor.r = 1.0;
1046             this._startColor.g = 1.0;
1047             this._startColor.b = 1.0;
1048             this._startColor.a = 1.0;
1049             this._startColorVar.r = 0.0;
1050             this._startColorVar.g = 0.0;
1051             this._startColorVar.b = 0.0;
1052             this._startColorVar.a = 0.0;
1053             this._endColor.r = 1.0;
1054             this._endColor.g = 1.0;
1055             this._endColor.b = 1.0;
1056             this._endColor.a = 0.0;
1057             this._endColorVar.r = 0.0;
1058             this._endColorVar.g = 0.0;
1059             this._endColorVar.b = 0.0;
1060             this._endColorVar.a = 0.0;
1061 
1062             // additive
1063             this.setBlendAdditive(false);
1064             return true;
1065         }
1066         return false;
1067     }
1068 });
1069 
1070 /**
1071  * Create a snow particle system
1072  * @return {cc.ParticleSnow}
1073  *
1074  * @example
1075  * var emitter = cc.ParticleSnow.create();
1076  */
1077 cc.ParticleSnow.create = function () {
1078     var ret = new cc.ParticleSnow();
1079     if (ret.init()) {
1080         return ret;
1081     }
1082     return null;
1083 };
1084 
1085 //! @brief A rain particle system
1086 /**
1087  * A rain particle system
1088  * @class
1089  * @extends cc.ParticleSystem
1090  *
1091  * @example
1092  * var emitter = cc.ParticleRain.create();
1093  */
1094 cc.ParticleRain = cc.ParticleSystem.extend(/** @lends cc.ParticleRain# */{
1095     /**
1096      * initialize a rain particle system
1097      * @return {Boolean}
1098      */
1099     init:function () {
1100         return this.initWithTotalParticles((cc.renderContextType === cc.WEBGL) ? 1000 : 300);
1101     },
1102 
1103     /**
1104      * initialize a rain particle system with number Of Particles
1105      * @param {Number} numberOfParticles
1106      * @return {Boolean}
1107      */
1108     initWithTotalParticles:function (numberOfParticles) {
1109         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
1110             // duration
1111             this._duration = cc.PARTICLE_DURATION_INFINITY;
1112 
1113             this._emitterMode = cc.PARTICLE_MODE_GRAVITY;
1114 
1115             // Gravity Mode: gravity
1116             this.modeA.gravity = cc.p(10, -10);
1117 
1118             // Gravity Mode: radial
1119             this.modeA.radialAccel = 0;
1120             this.modeA.radialAccelVar = 1;
1121 
1122             // Gravity Mode: tagential
1123             this.modeA.tangentialAccel = 0;
1124             this.modeA.tangentialAccelVar = 1;
1125 
1126             // Gravity Mode: speed of particles
1127             this.modeA.speed = 130;
1128             this.modeA.speedVar = 30;
1129 
1130             // angle
1131             this._angle = -90;
1132             this._angleVar = 5;
1133 
1134 
1135             // emitter position
1136             var winSize = cc.Director.getInstance().getWinSize();
1137             this.setPosition(winSize.width / 2, winSize.height);
1138             this._posVar = cc.p(winSize.width / 2, 0);
1139 
1140             // life of particles
1141             this._life = 4.5;
1142             this._lifeVar = 0;
1143 
1144             // size, in pixels
1145             this._startSize = 4.0;
1146             this._startSizeVar = 2.0;
1147             this._endSize = cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE;
1148 
1149             // emits per second
1150             this._emissionRate = 20;
1151 
1152             // color of particles
1153             this._startColor.r = 0.7;
1154             this._startColor.g = 0.8;
1155             this._startColor.b = 1.0;
1156             this._startColor.a = 1.0;
1157             this._startColorVar.r = 0.0;
1158             this._startColorVar.g = 0.0;
1159             this._startColorVar.b = 0.0;
1160             this._startColorVar.a = 0.0;
1161             this._endColor.r = 0.7;
1162             this._endColor.g = 0.8;
1163             this._endColor.b = 1.0;
1164             this._endColor.a = 0.5;
1165             this._endColorVar.r = 0.0;
1166             this._endColorVar.g = 0.0;
1167             this._endColorVar.b = 0.0;
1168             this._endColorVar.a = 0.0;
1169 
1170             // additive
1171             this.setBlendAdditive(false);
1172             return true;
1173         }
1174         return false;
1175     }
1176 });
1177 
1178 /**
1179  * Create a rain particle system
1180  * @return {cc.ParticleRain}
1181  *
1182  * @example
1183  * var emitter = cc.ParticleRain.create();
1184  */
1185 cc.ParticleRain.create = function () {
1186     var ret = new cc.ParticleRain();
1187     if (ret.init()) {
1188         return ret;
1189     }
1190     return null;
1191 };
1192