1 /****************************************************************************
  2  Copyright (c) 2008-2010 Ricardo Quesada
  3  Copyright (c) 2011-2012 cocos2d-x.org
  4  Copyright (c) 2013-2014 Chukong Technologies 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      * @constructor
 38      */
 39     ctor:function () {
 40         cc.ParticleSystem.prototype.ctor.call(this, (cc._renderType === cc._RENDER_TYPE_WEBGL) ? 300 : 150);
 41     },
 42 
 43     /**
 44      * initialize a fire particle system with number Of Particles
 45      * @param {Number} numberOfParticles
 46      * @return {Boolean}
 47      */
 48     initWithTotalParticles:function (numberOfParticles) {
 49         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
 50             // duration
 51             this.setDuration(cc.ParticleSystem.DURATION_INFINITY);
 52 
 53             // Gravity Mode
 54             this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
 55 
 56 
 57             // Gravity Mode: gravity
 58             this.setGravity(cc.p(0, 0));
 59 
 60             // Gravity Mode: radial acceleration
 61             this.setRadialAccel(0);
 62             this.setRadialAccelVar(0);
 63 
 64             // Gravity Mode: speed of particles
 65             this.setSpeed(60);
 66             this.setSpeedVar(20);
 67 
 68             // starting angle
 69             this.setAngle(90);
 70             this.setAngleVar(10);
 71 
 72             // emitter position
 73             var winSize = cc.director.getWinSize();
 74             this.setPosition(winSize.width / 2, 60);
 75             this.setPosVar(cc.p(40, 20));
 76 
 77             // life of particles
 78             this.setLife(3);
 79             this.setLifeVar(0.25);
 80 
 81 
 82             // size, in pixels
 83             this.setStartSize(54.0);
 84             this.setStartSizeVar(10.0);
 85             this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
 86 
 87             // emits per frame
 88             this.setEmissionRate(this.getTotalParticles() / this.getLife());
 89 
 90             // color of particles
 91             this.setStartColor(cc.color(194,64,31,255));
 92             this.setStartColorVar(cc.color(0,0,0,0));
 93             this.setEndColor(cc.color(0,0,0,255));
 94             this.setEndColorVar(cc.color(0,0,0,0));
 95 
 96             // additive
 97             this.setBlendAdditive(true);
 98             return true;
 99         }
100         return false;
101     }
102 });
103 
104 /**
105  * Create a fire particle system
106  * @deprecated
107  * @return {cc.ParticleFire}
108  *
109  * @example
110  * var emitter = cc.ParticleFire.create();
111  */
112 cc.ParticleFire.create = function () {
113     return new cc.ParticleFire();
114 };
115 
116 /**
117  * A fireworks particle system
118  * @class
119  * @extends cc.ParticleSystem
120  *
121  * @example
122  * var emitter = cc.ParticleFireworks.create();
123  */
124 cc.ParticleFireworks = cc.ParticleSystem.extend(/** @lends cc.ParticleFireworks# */{
125 
126     /**
127      * @constructor
128      */
129     ctor:function () {
130         cc.ParticleSystem.prototype.ctor.call(this, (cc._renderType === cc._RENDER_TYPE_WEBGL) ? 1500 : 150);
131     },
132 
133     /**
134      * initialize a fireworks particle system with number Of Particles
135      * @param {Number} numberOfParticles
136      * @return {Boolean}
137      */
138     initWithTotalParticles:function (numberOfParticles) {
139         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
140             // duration
141             this.setDuration(cc.ParticleSystem.DURATION_INFINITY);
142 
143             // Gravity Mode
144             this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
145 
146             // Gravity Mode: gravity
147             this.setGravity(cc.p(0, -90));
148 
149             // Gravity Mode:  radial
150             this.setRadialAccel(0);
151             this.setRadialAccelVar(0);
152 
153             //  Gravity Mode: speed of particles
154             this.setSpeed(180);
155             this.setSpeedVar(50);
156 
157             // emitter position
158             var winSize = cc.director.getWinSize();
159             this.setPosition(winSize.width / 2, winSize.height / 2);
160 
161             // angle
162             this.setAngle(90);
163             this.setAngleVar(20);
164 
165             // life of particles
166             this.setLife(3.5);
167             this.setLifeVar(1);
168 
169             // emits per frame
170             this.setEmissionRate(this.getTotalParticles() / this.getLife());
171 
172             // color of particles
173             this.setStartColor(cc.color(128,128,128,255));
174             this.setStartColorVar(cc.color(128,128,128,255));
175             this.setEndColor(cc.color(26,26,26,51));
176             this.setEndColorVar(cc.color(26,26,26,51));
177 
178             // size, in pixels
179             this.setStartSize(8.0);
180             this.setStartSizeVar(2.0);
181             this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
182 
183             // additive
184             this.setBlendAdditive(false);
185             return true;
186         }
187         return false;
188     }
189 });
190 
191 /**
192  * Create a fireworks particle system
193  * @deprecated
194  * @return {cc.ParticleFireworks}
195  *
196  * @example
197  * var emitter = cc.ParticleFireworks.create();
198  */
199 cc.ParticleFireworks.create = function () {
200     return new cc.ParticleFireworks();
201 };
202 
203 /**
204  * A sun particle system
205  * @class
206  * @extends cc.ParticleSystem
207  *
208  * @example
209  * var emitter = cc.ParticleSun.create();
210  */
211 cc.ParticleSun = cc.ParticleSystem.extend(/** @lends cc.ParticleSun# */{
212 
213     /**
214      * @constructor
215      */
216     ctor:function () {
217         cc.ParticleSystem.prototype.ctor.call(this, (cc._renderType === cc._RENDER_TYPE_WEBGL) ? 350 : 150);
218     },
219 
220     /**
221      * initialize a sun particle system with number Of Particles
222      * @param {Number} numberOfParticles
223      * @return {Boolean}
224      */
225     initWithTotalParticles:function (numberOfParticles) {
226         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
227             // additive
228             this.setBlendAdditive(true);
229 
230             // duration
231             this.setDuration(cc.ParticleSystem.DURATION_INFINITY);
232 
233             // Gravity Mode
234             this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
235 
236             // Gravity Mode: gravity
237             this.setGravity(cc.p(0, 0));
238 
239             // Gravity mode: radial acceleration
240             this.setRadialAccel(0);
241             this.setRadialAccelVar(0);
242 
243             // Gravity mode: speed of particles
244             this.setSpeed(20);
245             this.setSpeedVar(5);
246 
247             // angle
248             this.setAngle(90);
249             this.setAngleVar(360);
250 
251             // emitter position
252             var winSize = cc.director.getWinSize();
253             this.setPosition(winSize.width / 2, winSize.height / 2);
254             this.setPosVar(cc.p(0,0));
255 
256             // life of particles
257             this.setLife(1);
258             this.setLifeVar(0.5);
259 
260             // size, in pixels
261             this.setStartSize(30.0);
262             this.setStartSizeVar(10.0);
263             this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
264 
265             // emits per seconds
266             this.setEmissionRate(this.getTotalParticles() / this.getLife());
267 
268             // color of particles
269             this.setStartColor(cc.color(194, 64, 31, 255));
270             this.setStartColorVar(cc.color(0, 0, 0, 0));
271             this.setEndColor(cc.color(0, 0, 0, 255));
272             this.setEndColorVar(cc.color(0, 0, 0, 0));
273 
274             return true;
275         }
276         return false;
277     }
278 });
279 
280 /**
281  * Create a sun particle system
282  * @deprecated
283  * @return {cc.ParticleSun}
284  *
285  * @example
286  * var emitter = cc.ParticleSun.create();
287  */
288 cc.ParticleSun.create = function () {
289     return new cc.ParticleSun();
290 };
291 
292 //! @brief A  particle system
293 /**
294  * A galaxy particle system
295  * @class
296  * @extends cc.ParticleSystem
297  *
298  * @example
299  * var emitter = cc.ParticleGalaxy.create();
300  */
301 cc.ParticleGalaxy = cc.ParticleSystem.extend(/** @lends cc.ParticleGalaxy# */{
302 
303     /**
304      * @constructor
305      */
306     ctor:function () {
307         cc.ParticleSystem.prototype.ctor.call(this, (cc._renderType === cc._RENDER_TYPE_WEBGL) ? 200 : 100);
308     },
309 
310     /**
311      * initialize a galaxy particle system with number Of Particles
312      * @param {Number} numberOfParticles
313      * @return {Boolean}
314      */
315     initWithTotalParticles:function (numberOfParticles) {
316         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
317             // duration
318             this.setDuration(cc.ParticleSystem.DURATION_INFINITY);
319 
320             // Gravity Mode
321             this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
322 
323             // Gravity Mode: gravity
324             this.setGravity(cc.p(0, 0));
325 
326             // Gravity Mode: speed of particles
327             this.setSpeed(60);
328             this.setSpeedVar(10);
329 
330             // Gravity Mode: radial
331             this.setRadialAccel(-80);
332             this.setRadialAccelVar(0);
333 
334             // Gravity Mode: tangential
335             this.setTangentialAccel(80);
336             this.setTangentialAccelVar(0);
337 
338             // angle
339             this.setAngle(90);
340             this.setAngleVar(360);
341 
342             // emitter position
343             var winSize = cc.director.getWinSize();
344             this.setPosition(winSize.width / 2, winSize.height / 2);
345             this.setPosVar(cc.p(0,0));
346 
347             // life of particles
348             this.setLife(4);
349             this.setLifeVar(1);
350 
351             // size, in pixels
352             this.setStartSize(37.0);
353             this.setStartSizeVar(10.0);
354             this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
355 
356             // emits per second
357             this.setEmissionRate(this.getTotalParticles() / this.getLife());
358 
359             // color of particles
360             this.setStartColor(cc.color(31, 64, 194, 255));
361             this.setStartColorVar(cc.color(0, 0, 0, 0));
362             this.setEndColor(cc.color(0, 0, 0, 255));
363             this.setEndColorVar(cc.color(0, 0, 0, 0));
364 
365             // additive
366             this.setBlendAdditive(true);
367             return true;
368         }
369         return false;
370     }
371 });
372 /**
373  * Create a galaxy particle system
374  * @deprecated
375  * @return {cc.ParticleGalaxy}
376  *
377  * @example
378  * var emitter = cc.ParticleGalaxy.create();
379  */
380 cc.ParticleGalaxy.create = function () {
381     return new cc.ParticleGalaxy();
382 };
383 
384 /**
385  * A flower particle system
386  * @class
387  * @extends cc.ParticleSystem
388  *
389  * @example
390  * var emitter = cc.ParticleFlower.create();
391  */
392 cc.ParticleFlower = cc.ParticleSystem.extend(/** @lends cc.ParticleFlower# */{
393 
394     ctor : function () {
395         cc.ParticleSystem.prototype.ctor.call(this, (cc._renderType === cc._RENDER_TYPE_WEBGL) ? 250 : 100);
396     },
397 
398     /**
399      * initialize a flower particle system with number Of Particles
400      * @param {Number} numberOfParticles
401      * @return {Boolean}
402      */
403     initWithTotalParticles:function (numberOfParticles) {
404         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
405             // duration
406             this.setDuration(cc.ParticleSystem.DURATION_INFINITY);
407 
408             // Gravity Mode
409             this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
410 
411             // Gravity Mode: gravity
412             this.setGravity(cc.p(0, 0));
413 
414             // Gravity Mode: speed of particles
415             this.setSpeed(80);
416             this.setSpeedVar(10);
417 
418             // Gravity Mode: radial
419             this.setRadialAccel(-60);
420             this.setRadialAccelVar(0);
421 
422             // Gravity Mode: tangential
423             this.setTangentialAccel(15);
424             this.setTangentialAccelVar(0);
425 
426             // angle
427             this.setAngle(90);
428             this.setAngleVar(360);
429 
430             // emitter position
431             var winSize = cc.director.getWinSize();
432             this.setPosition(winSize.width / 2, winSize.height / 2);
433             this.setPosVar(cc.p(0,0));
434 
435             // life of particles
436             this.setLife(4);
437             this.setLifeVar(1);
438 
439             // size, in pixels
440             this.setStartSize(30.0);
441             this.setStartSizeVar(10.0);
442             this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
443 
444             // emits per second
445             this.setEmissionRate(this.getTotalParticles() / this.getLife());
446 
447             // color of particles
448             this.setStartColor(cc.color(128, 128, 128, 255));
449             this.setStartColorVar(cc.color(128, 128, 128, 128));
450             this.setEndColor(cc.color(0, 0, 0, 255));
451             this.setEndColorVar(cc.color(0, 0, 0, 0));
452 
453             // additive
454             this.setBlendAdditive(true);
455             return true;
456         }
457         return false;
458     }
459 });
460 
461 /**
462  * Create a flower particle system
463  * @deprecated
464  * @return {cc.ParticleFlower}
465  *
466  * @example
467  * var emitter = cc.ParticleFlower.create();
468  */
469 cc.ParticleFlower.create = function () {
470     return new cc.ParticleFlower();
471 };
472 
473 //! @brief A meteor particle system
474 /**
475  * A meteor particle system
476  * @class
477  * @extends cc.ParticleSystem
478  *
479  * @example
480  * var emitter = cc.ParticleMeteor.create();
481  */
482 cc.ParticleMeteor = cc.ParticleSystem.extend(/** @lends cc.ParticleMeteor# */{
483 
484     /**
485      * @constructor
486      */
487     ctor:function () {
488         cc.ParticleSystem.prototype.ctor.call(this, (cc._renderType === cc._RENDER_TYPE_WEBGL) ? 150 : 100);
489     },
490 
491     /**
492      * initialize a meteor particle system with number Of Particles
493      * @param {Number} numberOfParticles
494      * @return {Boolean}
495      */
496     initWithTotalParticles:function (numberOfParticles) {
497         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
498             // duration
499             this.setDuration(cc.ParticleSystem.DURATION_INFINITY);
500 
501             // Gravity Mode
502             this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
503 
504             // Gravity Mode: gravity
505             this.setGravity(cc.p(-200, 200));
506 
507             // Gravity Mode: speed of particles
508             this.setSpeed(15);
509             this.setSpeedVar(5);
510 
511             // Gravity Mode: radial
512             this.setRadialAccel(0);
513             this.setRadialAccelVar(0);
514 
515             // Gravity Mode: tangential
516             this.setTangentialAccel(0);
517             this.setTangentialAccelVar(0);
518 
519             // angle
520             this.setAngle(90);
521             this.setAngleVar(360);
522 
523             // emitter position
524             var winSize = cc.director.getWinSize();
525             this.setPosition(winSize.width / 2, winSize.height / 2);
526             this.setPosVar(cc.p(0,0));
527 
528             // life of particles
529             this.setLife(2);
530             this.setLifeVar(1);
531 
532             // size, in pixels
533             this.setStartSize(60.0);
534             this.setStartSizeVar(10.0);
535             this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
536 
537             // emits per second
538             this.setEmissionRate(this.getTotalParticles() / this.getLife());
539 
540             // color of particles
541             this.setStartColor(cc.color(51, 102, 179));
542             this.setStartColorVar(cc.color(0, 0, 51, 26));
543             this.setEndColor(cc.color(0, 0, 0, 255));
544             this.setEndColorVar(cc.color(0, 0, 0, 0));
545 
546             // additive
547             this.setBlendAdditive(true);
548             return true;
549         }
550         return false;
551     }
552 });
553 
554 /**
555  * Create a meteor particle system
556  * @deprecated
557  * @return {cc.ParticleMeteor}
558  *
559  * @example
560  * var emitter = cc.ParticleMeteor.create();
561  */
562 cc.ParticleMeteor.create = function () {
563     return new cc.ParticleMeteor();
564 };
565 
566 /**
567  * A spiral particle system
568  * @class
569  * @extends cc.ParticleSystem
570  *
571  * @example
572  * var emitter = cc.ParticleSpiral.create();
573  */
574 cc.ParticleSpiral = cc.ParticleSystem.extend(/** @lends cc.ParticleSpiral# */{
575 
576     /**
577      * @constructor
578      */
579     ctor:function() {
580         cc.ParticleSystem.prototype.ctor.call(this,(cc._renderType === cc._RENDER_TYPE_WEBGL) ? 500 : 100);
581     },
582 
583     /**
584      * initialize a spiral particle system with number Of Particles
585      * @param {Number} numberOfParticles
586      * @return {Boolean}
587      */
588     initWithTotalParticles:function (numberOfParticles) {
589         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
590             // duration
591             this.setDuration(cc.ParticleSystem.DURATION_INFINITY);
592 
593             // Gravity Mode
594             this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
595 
596             // Gravity Mode: gravity
597             this.setGravity(cc.p(0, 0));
598 
599             // Gravity Mode: speed of particles
600             this.setSpeed(150);
601             this.setSpeedVar(0);
602 
603             // Gravity Mode: radial
604             this.setRadialAccel(-380);
605             this.setRadialAccelVar(0);
606 
607             // Gravity Mode: tangential
608             this.setTangentialAccel(45);
609             this.setTangentialAccelVar(0);
610 
611             // angle
612             this.setAngle(90);
613             this.setAngleVar(0);
614 
615             // emitter position
616             var winSize = cc.director.getWinSize();
617             this.setPosition(winSize.width / 2, winSize.height / 2);
618             this.setPosVar(cc.p(0,0));
619 
620             // life of particles
621             this.setLife(12);
622             this.setLifeVar(0);
623 
624             // size, in pixels
625             this.setStartSize(20.0);
626             this.setStartSizeVar(0.0);
627             this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
628 
629             // emits per second
630             this.setEmissionRate(this.getTotalParticles() / this.getLife());
631 
632             // color of particles
633             this.setStartColor(cc.color(128,128,128,255));
634             this.setStartColorVar(cc.color(128,128,128,0));
635             this.setEndColor(cc.color(128,128,128,255));
636             this.setEndColorVar(cc.color(128,128,128,0));
637 
638             // additive
639             this.setBlendAdditive(false);
640             return true;
641         }
642         return false;
643     }
644 });
645 
646 /**
647  * Create a spiral particle system
648  * @deprecated
649  * @return {cc.ParticleSpiral}
650  *
651  * @example
652  * var emitter = cc.ParticleSpiral.create();
653  */
654 cc.ParticleSpiral.create = function () {
655     return new cc.ParticleSpiral();
656 };
657 
658 /**
659  * An explosion particle system
660  * @class
661  * @extends cc.ParticleSystem
662  *
663  * @example
664  * var emitter = cc.ParticleExplosion.create();
665  */
666 cc.ParticleExplosion = cc.ParticleSystem.extend(/** @lends cc.ParticleExplosion# */{
667 
668     /**
669      * @constructor
670      */
671     ctor:function () {
672         cc.ParticleSystem.prototype.ctor.call(this, (cc._renderType === cc._RENDER_TYPE_WEBGL) ? 700 : 300);
673     },
674 
675     /**
676      * initialize an explosion particle system with number Of Particles
677      * @param {Number} numberOfParticles
678      * @return {Boolean}
679      */
680     initWithTotalParticles:function (numberOfParticles) {
681         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
682             // duration
683             this.setDuration(0.1);
684 
685             this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
686 
687             // Gravity Mode: gravity
688             this.setGravity(cc.p(0, 0));
689 
690             // Gravity Mode: speed of particles
691             this.setSpeed(70);
692             this.setSpeedVar(40);
693 
694             // Gravity Mode: radial
695             this.setRadialAccel(0);
696             this.setRadialAccelVar(0);
697 
698             // Gravity Mode: tangential
699             this.setTangentialAccel(0);
700             this.setTangentialAccelVar(0);
701 
702             // angle
703             this.setAngle(90);
704             this.setAngleVar(360);
705 
706             // emitter position
707             var winSize = cc.director.getWinSize();
708             this.setPosition(winSize.width / 2, winSize.height / 2);
709             this.setPosVar(cc.p(0,0));
710 
711             // life of particles
712             this.setLife(5.0);
713             this.setLifeVar(2);
714 
715             // size, in pixels
716             this.setStartSize(15.0);
717             this.setStartSizeVar(10.0);
718             this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
719 
720             // emits per second
721             this.setEmissionRate(this.getTotalParticles() / this.getDuration());
722 
723             // color of particles
724             this.setStartColor(cc.color(179, 26, 51, 255));
725             this.setStartColorVar(cc.color(128, 128, 128, 0));
726             this.setEndColor(cc.color(128, 128, 128, 0));
727             this.setEndColorVar(cc.color(128, 128, 128, 0));
728 
729             // additive
730             this.setBlendAdditive(false);
731             return true;
732         }
733         return false;
734     }
735 });
736 
737 /**
738  * Create an explosion particle system
739  * @deprecated
740  * @return {cc.ParticleExplosion}
741  *
742  * @example
743  * var emitter = cc.ParticleExplosion.create();
744  */
745 cc.ParticleExplosion.create = function () {
746     return new cc.ParticleExplosion();
747 };
748 
749 /**
750  * A smoke particle system
751  * @class
752  * @extends cc.ParticleSystem
753  *
754  * @example
755  * var emitter = cc.ParticleSmoke.create();
756  */
757 cc.ParticleSmoke = cc.ParticleSystem.extend(/** @lends cc.ParticleSmoke# */{
758 
759     /**
760      * @contructor
761      */
762     ctor:function () {
763         cc.ParticleSystem.prototype.ctor.call(this, (cc._renderType === cc._RENDER_TYPE_WEBGL) ? 200 : 100);
764     },
765 
766     /**
767      * initialize a smoke particle system with number Of Particles
768      * @param {Number} numberOfParticles
769      * @return {Boolean}
770      */
771     initWithTotalParticles:function (numberOfParticles) {
772         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
773             // duration
774             this.setDuration(cc.ParticleSystem.DURATION_INFINITY);
775 
776             // Emitter mode: Gravity Mode
777             this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
778 
779             // Gravity Mode: gravity
780             this.setGravity(cc.p(0, 0));
781 
782             // Gravity Mode: radial acceleration
783             this.setRadialAccel(0);
784             this.setRadialAccelVar(0);
785 
786             // Gravity Mode: speed of particles
787             this.setSpeed(25);
788             this.setSpeedVar(10);
789 
790             // angle
791             this.setAngle(90);
792             this.setAngleVar(5);
793 
794             // emitter position
795             var winSize = cc.director.getWinSize();
796             this.setPosition(winSize.width / 2, 0);
797             this.setPosVar(cc.p(20, 0));
798 
799             // life of particles
800             this.setLife(4);
801             this.setLifeVar(1);
802 
803             // size, in pixels
804             this.setStartSize(60.0);
805             this.setStartSizeVar(10.0);
806             this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
807 
808             // emits per frame
809             this.setEmissionRate(this.getTotalParticles() / this.getLife());
810 
811             // color of particles
812             this.setStartColor(cc.color(204, 204, 204, 255));
813             this.setStartColorVar(cc.color(5, 5, 5, 0));
814             this.setEndColor(cc.color(0, 0, 0, 255));
815             this.setEndColorVar(cc.color(0, 0, 0, 0));
816 
817             // additive
818             this.setBlendAdditive(false);
819             return true;
820         }
821         return false;
822     }
823 });
824 
825 /**
826  * Create a smoke particle system
827  * @deprecated
828  * @return {cc.ParticleSmoke}
829  *
830  * @example
831  * var emitter = cc.ParticleFireworks.create();
832  */
833 cc.ParticleSmoke.create = function () {
834     return new cc.ParticleSmoke();
835 };
836 
837 /**
838  * A snow particle system
839  * @class
840  * @extends cc.ParticleSystem
841  *
842  * @example
843  * var emitter = cc.ParticleSnow.create();
844  */
845 cc.ParticleSnow = cc.ParticleSystem.extend(/** @lends cc.ParticleSnow# */{
846 
847     /**
848      * @constructor
849      */
850     ctor:function () {
851         cc.ParticleSystem.prototype.ctor.call(this, (cc._renderType === cc._RENDER_TYPE_WEBGL) ? 700 : 250);
852     },
853 
854     /**
855      * initialize a snow particle system with number Of Particles
856      * @param {Number} numberOfParticles
857      * @return {Boolean}
858      */
859     initWithTotalParticles:function (numberOfParticles) {
860         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
861             // duration
862             this.setDuration(cc.ParticleSystem.DURATION_INFINITY);
863 
864             // set gravity mode.
865             this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
866 
867             // Gravity Mode: gravity
868             this.setGravity(cc.p(0, -1));
869 
870             // Gravity Mode: speed of particles
871             this.setSpeed(5);
872             this.setSpeedVar(1);
873 
874             // Gravity Mode: radial
875             this.setRadialAccel(0);
876             this.setRadialAccelVar(1);
877 
878             // Gravity mode: tangential
879             this.setTangentialAccel(0);
880             this.setTangentialAccelVar(1);
881 
882             // emitter position
883             var winSize = cc.director.getWinSize();
884             this.setPosition(winSize.width / 2, winSize.height + 10);
885             this.setPosVar(cc.p(winSize.width / 2, 0));
886 
887             // angle
888             this.setAngle(-90);
889             this.setAngleVar(5);
890 
891             // life of particles
892             this.setLife(45);
893             this.setLifeVar(15);
894 
895             // size, in pixels
896             this.setStartSize(10.0);
897             this.setStartSizeVar(5.0);
898             this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
899 
900             // emits per second
901             this.setEmissionRate(10);
902 
903             // color of particles
904             this.setStartColor(cc.color(255, 255, 255, 255));
905             this.setStartColorVar(cc.color(0, 0, 0, 0));
906             this.setEndColor(cc.color(255, 255, 255, 0));
907             this.setEndColorVar(cc.color(0, 0, 0, 0));
908 
909             // additive
910             this.setBlendAdditive(false);
911             return true;
912         }
913         return false;
914     }
915 });
916 
917 /**
918  * Create a snow particle system
919  * @deprecated
920  * @return {cc.ParticleSnow}
921  *
922  * @example
923  * var emitter = cc.ParticleSnow.create();
924  */
925 cc.ParticleSnow.create = function () {
926     return new cc.ParticleSnow();
927 };
928 
929 //! @brief A rain particle system
930 /**
931  * A rain particle system
932  * @class
933  * @extends cc.ParticleSystem
934  *
935  * @example
936  * var emitter = cc.ParticleRain.create();
937  */
938 cc.ParticleRain = cc.ParticleSystem.extend(/** @lends cc.ParticleRain# */{
939 
940     /**
941      * @constructor
942      */
943     ctor:function () {
944         cc.ParticleSystem.prototype.ctor.call(this, (cc._renderType === cc._RENDER_TYPE_WEBGL) ? 1000 : 300);
945     },
946 
947     /**
948      * initialize a rain particle system with number Of Particles
949      * @param {Number} numberOfParticles
950      * @return {Boolean}
951      */
952     initWithTotalParticles:function (numberOfParticles) {
953         if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
954             // duration
955             this.setDuration(cc.ParticleSystem.DURATION_INFINITY);
956 
957             this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
958 
959             // Gravity Mode: gravity
960             this.setGravity(cc.p(10, -10));
961 
962             // Gravity Mode: radial
963             this.setRadialAccel(0);
964             this.setRadialAccelVar(1);
965 
966             // Gravity Mode: tangential
967             this.setTangentialAccel(0);
968             this.setTangentialAccelVar(1);
969 
970             // Gravity Mode: speed of particles
971             this.setSpeed(130);
972             this.setSpeedVar(30);
973 
974             // angle
975             this.setAngle(-90);
976             this.setAngleVar(5);
977 
978 
979             // emitter position
980             var winSize = cc.director.getWinSize();
981             this.setPosition(winSize.width / 2, winSize.height);
982             this.setPosVar(cc.p(winSize.width / 2, 0));
983 
984             // life of particles
985             this.setLife(4.5);
986             this.setLifeVar(0);
987 
988             // size, in pixels
989             this.setStartSize(4.0);
990             this.setStartSizeVar(2.0);
991             this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
992 
993             // emits per second
994             this.setEmissionRate(20);
995 
996             // color of particles
997             this.setStartColor(cc.color(179, 204, 255, 255));
998             this.setStartColorVar(cc.color(0, 0, 0, 0));
999             this.setEndColor(cc.color(179, 204, 255, 128));
1000             this.setEndColorVar(cc.color(0, 0, 0, 0));
1001 
1002             // additive
1003             this.setBlendAdditive(false);
1004             return true;
1005         }
1006         return false;
1007     }
1008 });
1009 
1010 /**
1011  * Create a rain particle system
1012  * @deprecated
1013  * @return {cc.ParticleRain}
1014  *
1015  * @example
1016  * var emitter = cc.ParticleRain.create();
1017  */
1018 cc.ParticleRain.create = function () {
1019     return new cc.ParticleRain();
1020 };
1021