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