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