CCParticleExamples.js 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  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. http://www.cocos2d-x.org
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. ****************************************************************************/
  22. /**
  23. * A fire particle system
  24. * @class
  25. * @extends cc.ParticleSystem
  26. *
  27. * @example
  28. * var emitter = new cc.ParticleFire();
  29. */
  30. cc.ParticleFire = cc.ParticleSystem.extend(/** @lends cc.ParticleFire# */{
  31. /**
  32. * <p>The cc.ParticleFire's constructor. <br/>
  33. * This function will automatically be invoked when you create a node using new construction: "var node = new cc.ParticleFire()".<br/>
  34. * Override it to extend its behavior, remember to call "this._super()" in the extended "ctor" function.</p>
  35. */
  36. ctor:function () {
  37. cc.ParticleSystem.prototype.ctor.call(this, (cc._renderType === cc._RENDER_TYPE_WEBGL) ? 300 : 150);
  38. },
  39. /**
  40. * initialize a fire particle system with number Of Particles
  41. * @param {Number} numberOfParticles
  42. * @return {Boolean}
  43. */
  44. initWithTotalParticles:function (numberOfParticles) {
  45. if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
  46. // duration
  47. this.setDuration(cc.ParticleSystem.DURATION_INFINITY);
  48. // Gravity Mode
  49. this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
  50. // Gravity Mode: gravity
  51. this.setGravity(cc.p(0, 0));
  52. // Gravity Mode: radial acceleration
  53. this.setRadialAccel(0);
  54. this.setRadialAccelVar(0);
  55. // Gravity Mode: speed of particles
  56. this.setSpeed(60);
  57. this.setSpeedVar(20);
  58. // starting angle
  59. this.setAngle(90);
  60. this.setAngleVar(10);
  61. // emitter position
  62. var winSize = cc.director.getWinSize();
  63. this.setPosition(winSize.width / 2, 60);
  64. this.setPosVar(cc.p(40, 20));
  65. // life of particles
  66. this.setLife(3);
  67. this.setLifeVar(0.25);
  68. // size, in pixels
  69. this.setStartSize(54.0);
  70. this.setStartSizeVar(10.0);
  71. this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
  72. // emits per frame
  73. this.setEmissionRate(this.getTotalParticles() / this.getLife());
  74. // color of particles
  75. this.setStartColor(cc.color(194,64,31,255));
  76. this.setStartColorVar(cc.color(0,0,0,0));
  77. this.setEndColor(cc.color(0,0,0,255));
  78. this.setEndColorVar(cc.color(0,0,0,0));
  79. // additive
  80. this.setBlendAdditive(true);
  81. return true;
  82. }
  83. return false;
  84. }
  85. });
  86. /**
  87. * Create a fire particle system
  88. * @deprecated since v3.0 please use new cc.ParticleFire() instead
  89. * @return {cc.ParticleFire}
  90. *
  91. * @example
  92. * var emitter = cc.ParticleFire.create();
  93. */
  94. cc.ParticleFire.create = function () {
  95. return new cc.ParticleFire();
  96. };
  97. /**
  98. * A fireworks particle system
  99. * @class
  100. * @extends cc.ParticleSystem
  101. *
  102. * @example
  103. * var emitter = new cc.ParticleFireworks();
  104. */
  105. cc.ParticleFireworks = cc.ParticleSystem.extend(/** @lends cc.ParticleFireworks# */{
  106. /**
  107. * <p>The cc.ParticleFireworks's constructor. <br/>
  108. * This function will automatically be invoked when you create a node using new construction: "var node = new cc.ParticleFireworks()".<br/>
  109. * Override it to extend its behavior, remember to call "this._super()" in the extended "ctor" function.</p>
  110. */
  111. ctor:function () {
  112. cc.ParticleSystem.prototype.ctor.call(this, (cc._renderType === cc._RENDER_TYPE_WEBGL) ? 1500 : 150);
  113. },
  114. /**
  115. * initialize a fireworks particle system with number Of Particles
  116. * @param {Number} numberOfParticles
  117. * @return {Boolean}
  118. */
  119. initWithTotalParticles:function (numberOfParticles) {
  120. if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
  121. // duration
  122. this.setDuration(cc.ParticleSystem.DURATION_INFINITY);
  123. // Gravity Mode
  124. this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
  125. // Gravity Mode: gravity
  126. this.setGravity(cc.p(0, -90));
  127. // Gravity Mode: radial
  128. this.setRadialAccel(0);
  129. this.setRadialAccelVar(0);
  130. // Gravity Mode: speed of particles
  131. this.setSpeed(180);
  132. this.setSpeedVar(50);
  133. // emitter position
  134. var winSize = cc.director.getWinSize();
  135. this.setPosition(winSize.width / 2, winSize.height / 2);
  136. // angle
  137. this.setAngle(90);
  138. this.setAngleVar(20);
  139. // life of particles
  140. this.setLife(3.5);
  141. this.setLifeVar(1);
  142. // emits per frame
  143. this.setEmissionRate(this.getTotalParticles() / this.getLife());
  144. // color of particles
  145. this.setStartColor(cc.color(128,128,128,255));
  146. this.setStartColorVar(cc.color(128,128,128,255));
  147. this.setEndColor(cc.color(26,26,26,51));
  148. this.setEndColorVar(cc.color(26,26,26,51));
  149. // size, in pixels
  150. this.setStartSize(8.0);
  151. this.setStartSizeVar(2.0);
  152. this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
  153. // additive
  154. this.setBlendAdditive(false);
  155. return true;
  156. }
  157. return false;
  158. }
  159. });
  160. /**
  161. * Create a fireworks particle system
  162. * @deprecated since v3.0 please use new cc.ParticleFireworks() instead.
  163. * @return {cc.ParticleFireworks}
  164. *
  165. * @example
  166. * var emitter = cc.ParticleFireworks.create();
  167. */
  168. cc.ParticleFireworks.create = function () {
  169. return new cc.ParticleFireworks();
  170. };
  171. /**
  172. * A sun particle system
  173. * @class
  174. * @extends cc.ParticleSystem
  175. *
  176. * @example
  177. * var emitter = new cc.ParticleSun();
  178. */
  179. cc.ParticleSun = cc.ParticleSystem.extend(/** @lends cc.ParticleSun# */{
  180. /**
  181. * <p>The cc.ParticleSun's constructor. <br/>
  182. * This function will automatically be invoked when you create a node using new construction: "var node = new cc.ParticleSun()".<br/>
  183. * Override it to extend its behavior, remember to call "this._super()" in the extended "ctor" function.</p>
  184. */
  185. ctor:function () {
  186. cc.ParticleSystem.prototype.ctor.call(this, (cc._renderType === cc._RENDER_TYPE_WEBGL) ? 350 : 150);
  187. },
  188. /**
  189. * initialize a sun particle system with number Of Particles
  190. * @param {Number} numberOfParticles
  191. * @return {Boolean}
  192. */
  193. initWithTotalParticles:function (numberOfParticles) {
  194. if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
  195. // additive
  196. this.setBlendAdditive(true);
  197. // duration
  198. this.setDuration(cc.ParticleSystem.DURATION_INFINITY);
  199. // Gravity Mode
  200. this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
  201. // Gravity Mode: gravity
  202. this.setGravity(cc.p(0, 0));
  203. // Gravity mode: radial acceleration
  204. this.setRadialAccel(0);
  205. this.setRadialAccelVar(0);
  206. // Gravity mode: speed of particles
  207. this.setSpeed(20);
  208. this.setSpeedVar(5);
  209. // angle
  210. this.setAngle(90);
  211. this.setAngleVar(360);
  212. // emitter position
  213. var winSize = cc.director.getWinSize();
  214. this.setPosition(winSize.width / 2, winSize.height / 2);
  215. this.setPosVar(cc.p(0,0));
  216. // life of particles
  217. this.setLife(1);
  218. this.setLifeVar(0.5);
  219. // size, in pixels
  220. this.setStartSize(30.0);
  221. this.setStartSizeVar(10.0);
  222. this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
  223. // emits per seconds
  224. this.setEmissionRate(this.getTotalParticles() / this.getLife());
  225. // color of particles
  226. this.setStartColor(cc.color(194, 64, 31, 255));
  227. this.setStartColorVar(cc.color(0, 0, 0, 0));
  228. this.setEndColor(cc.color(0, 0, 0, 255));
  229. this.setEndColorVar(cc.color(0, 0, 0, 0));
  230. return true;
  231. }
  232. return false;
  233. }
  234. });
  235. /**
  236. * Create a sun particle system
  237. * @deprecated since v3.0 please use new cc.ParticleSun() instead.
  238. * @return {cc.ParticleSun}
  239. *
  240. * @example
  241. * var emitter = cc.ParticleSun.create();
  242. */
  243. cc.ParticleSun.create = function () {
  244. return new cc.ParticleSun();
  245. };
  246. //! @brief A particle system
  247. /**
  248. * A galaxy particle system
  249. * @class
  250. * @extends cc.ParticleSystem
  251. *
  252. * @example
  253. * var emitter = new cc.ParticleGalaxy();
  254. */
  255. cc.ParticleGalaxy = cc.ParticleSystem.extend(/** @lends cc.ParticleGalaxy# */{
  256. /**
  257. * <p>The cc.ParticleGalaxy's constructor. <br/>
  258. * This function will automatically be invoked when you create a node using new construction: "var node = new cc.ParticleGalaxy()".<br/>
  259. * Override it to extend its behavior, remember to call "this._super()" in the extended "ctor" function.</p>
  260. */
  261. ctor:function () {
  262. cc.ParticleSystem.prototype.ctor.call(this, (cc._renderType === cc._RENDER_TYPE_WEBGL) ? 200 : 100);
  263. },
  264. /**
  265. * initialize a galaxy particle system with number Of Particles
  266. * @param {Number} numberOfParticles
  267. * @return {Boolean}
  268. */
  269. initWithTotalParticles:function (numberOfParticles) {
  270. if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
  271. // duration
  272. this.setDuration(cc.ParticleSystem.DURATION_INFINITY);
  273. // Gravity Mode
  274. this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
  275. // Gravity Mode: gravity
  276. this.setGravity(cc.p(0, 0));
  277. // Gravity Mode: speed of particles
  278. this.setSpeed(60);
  279. this.setSpeedVar(10);
  280. // Gravity Mode: radial
  281. this.setRadialAccel(-80);
  282. this.setRadialAccelVar(0);
  283. // Gravity Mode: tangential
  284. this.setTangentialAccel(80);
  285. this.setTangentialAccelVar(0);
  286. // angle
  287. this.setAngle(90);
  288. this.setAngleVar(360);
  289. // emitter position
  290. var winSize = cc.director.getWinSize();
  291. this.setPosition(winSize.width / 2, winSize.height / 2);
  292. this.setPosVar(cc.p(0,0));
  293. // life of particles
  294. this.setLife(4);
  295. this.setLifeVar(1);
  296. // size, in pixels
  297. this.setStartSize(37.0);
  298. this.setStartSizeVar(10.0);
  299. this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
  300. // emits per second
  301. this.setEmissionRate(this.getTotalParticles() / this.getLife());
  302. // color of particles
  303. this.setStartColor(cc.color(31, 64, 194, 255));
  304. this.setStartColorVar(cc.color(0, 0, 0, 0));
  305. this.setEndColor(cc.color(0, 0, 0, 255));
  306. this.setEndColorVar(cc.color(0, 0, 0, 0));
  307. // additive
  308. this.setBlendAdditive(true);
  309. return true;
  310. }
  311. return false;
  312. }
  313. });
  314. /**
  315. * Create a galaxy particle system
  316. * @deprecated since v3.0 please use new cc.OarticleGalaxy() instead.
  317. * @return {cc.ParticleGalaxy}
  318. *
  319. * @example
  320. * var emitter = cc.ParticleGalaxy.create();
  321. */
  322. cc.ParticleGalaxy.create = function () {
  323. return new cc.ParticleGalaxy();
  324. };
  325. /**
  326. * A flower particle system
  327. * @class
  328. * @extends cc.ParticleSystem
  329. *
  330. * @example
  331. * var emitter = new cc.ParticleFlower();
  332. */
  333. cc.ParticleFlower = cc.ParticleSystem.extend(/** @lends cc.ParticleFlower# */{
  334. /**
  335. * <p>The cc.ParticleFlower's constructor. <br/>
  336. * This function will automatically be invoked when you create a node using new construction: "var node = new cc.ParticleFlower()".<br/>
  337. * Override it to extend its behavior, remember to call "this._super()" in the extended "ctor" function.</p>
  338. */
  339. ctor : function () {
  340. cc.ParticleSystem.prototype.ctor.call(this, (cc._renderType === cc._RENDER_TYPE_WEBGL) ? 250 : 100);
  341. },
  342. /**
  343. * initialize a flower particle system with number Of Particles
  344. * @param {Number} numberOfParticles
  345. * @return {Boolean}
  346. */
  347. initWithTotalParticles:function (numberOfParticles) {
  348. if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
  349. // duration
  350. this.setDuration(cc.ParticleSystem.DURATION_INFINITY);
  351. // Gravity Mode
  352. this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
  353. // Gravity Mode: gravity
  354. this.setGravity(cc.p(0, 0));
  355. // Gravity Mode: speed of particles
  356. this.setSpeed(80);
  357. this.setSpeedVar(10);
  358. // Gravity Mode: radial
  359. this.setRadialAccel(-60);
  360. this.setRadialAccelVar(0);
  361. // Gravity Mode: tangential
  362. this.setTangentialAccel(15);
  363. this.setTangentialAccelVar(0);
  364. // angle
  365. this.setAngle(90);
  366. this.setAngleVar(360);
  367. // emitter position
  368. var winSize = cc.director.getWinSize();
  369. this.setPosition(winSize.width / 2, winSize.height / 2);
  370. this.setPosVar(cc.p(0,0));
  371. // life of particles
  372. this.setLife(4);
  373. this.setLifeVar(1);
  374. // size, in pixels
  375. this.setStartSize(30.0);
  376. this.setStartSizeVar(10.0);
  377. this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
  378. // emits per second
  379. this.setEmissionRate(this.getTotalParticles() / this.getLife());
  380. // color of particles
  381. this.setStartColor(cc.color(128, 128, 128, 255));
  382. this.setStartColorVar(cc.color(128, 128, 128, 128));
  383. this.setEndColor(cc.color(0, 0, 0, 255));
  384. this.setEndColorVar(cc.color(0, 0, 0, 0));
  385. // additive
  386. this.setBlendAdditive(true);
  387. return true;
  388. }
  389. return false;
  390. }
  391. });
  392. /**
  393. * Create a flower particle system
  394. * @deprecated since v3.0 please use new cc.ParticleFlower() instead.
  395. * @return {cc.ParticleFlower}
  396. *
  397. * @example
  398. * var emitter = cc.ParticleFlower.create();
  399. */
  400. cc.ParticleFlower.create = function () {
  401. return new cc.ParticleFlower();
  402. };
  403. //! @brief A meteor particle system
  404. /**
  405. * A meteor particle system
  406. * @class
  407. * @extends cc.ParticleSystem
  408. *
  409. * @example
  410. * var emitter = new cc.ParticleMeteor();
  411. */
  412. cc.ParticleMeteor = cc.ParticleSystem.extend(/** @lends cc.ParticleMeteor# */{
  413. /**
  414. * <p>The cc.ParticleMeteor's constructor. <br/>
  415. * This function will automatically be invoked when you create a node using new construction: "var node = new cc.ParticleMeteor()".<br/>
  416. * Override it to extend its behavior, remember to call "this._super()" in the extended "ctor" function.</p>
  417. */
  418. ctor:function () {
  419. cc.ParticleSystem.prototype.ctor.call(this, (cc._renderType === cc._RENDER_TYPE_WEBGL) ? 150 : 100);
  420. },
  421. /**
  422. * initialize a meteor particle system with number Of Particles
  423. * @param {Number} numberOfParticles
  424. * @return {Boolean}
  425. */
  426. initWithTotalParticles:function (numberOfParticles) {
  427. if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
  428. // duration
  429. this.setDuration(cc.ParticleSystem.DURATION_INFINITY);
  430. // Gravity Mode
  431. this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
  432. // Gravity Mode: gravity
  433. this.setGravity(cc.p(-200, 200));
  434. // Gravity Mode: speed of particles
  435. this.setSpeed(15);
  436. this.setSpeedVar(5);
  437. // Gravity Mode: radial
  438. this.setRadialAccel(0);
  439. this.setRadialAccelVar(0);
  440. // Gravity Mode: tangential
  441. this.setTangentialAccel(0);
  442. this.setTangentialAccelVar(0);
  443. // angle
  444. this.setAngle(90);
  445. this.setAngleVar(360);
  446. // emitter position
  447. var winSize = cc.director.getWinSize();
  448. this.setPosition(winSize.width / 2, winSize.height / 2);
  449. this.setPosVar(cc.p(0,0));
  450. // life of particles
  451. this.setLife(2);
  452. this.setLifeVar(1);
  453. // size, in pixels
  454. this.setStartSize(60.0);
  455. this.setStartSizeVar(10.0);
  456. this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
  457. // emits per second
  458. this.setEmissionRate(this.getTotalParticles() / this.getLife());
  459. // color of particles
  460. this.setStartColor(cc.color(51, 102, 179));
  461. this.setStartColorVar(cc.color(0, 0, 51, 26));
  462. this.setEndColor(cc.color(0, 0, 0, 255));
  463. this.setEndColorVar(cc.color(0, 0, 0, 0));
  464. // additive
  465. this.setBlendAdditive(true);
  466. return true;
  467. }
  468. return false;
  469. }
  470. });
  471. /**
  472. * Create a meteor particle system
  473. * @deprecated since v3.0 please use new cc.ParticleMeteor() instead.
  474. * @return {cc.ParticleMeteor}
  475. *
  476. * @example
  477. * var emitter = cc.ParticleMeteor.create();
  478. */
  479. cc.ParticleMeteor.create = function () {
  480. return new cc.ParticleMeteor();
  481. };
  482. /**
  483. * A spiral particle system
  484. * @class
  485. * @extends cc.ParticleSystem
  486. *
  487. * @example
  488. * var emitter = new cc.ParticleSpiral();
  489. */
  490. cc.ParticleSpiral = cc.ParticleSystem.extend(/** @lends cc.ParticleSpiral# */{
  491. /**
  492. * <p>The cc.ParticleSpiral's constructor. <br/>
  493. * This function will automatically be invoked when you create a node using new construction: "var node = new cc.ParticleSpiral()".<br/>
  494. * Override it to extend its behavior, remember to call "this._super()" in the extended "ctor" function.</p>
  495. */
  496. ctor:function() {
  497. cc.ParticleSystem.prototype.ctor.call(this,(cc._renderType === cc._RENDER_TYPE_WEBGL) ? 500 : 100);
  498. },
  499. /**
  500. * initialize a spiral particle system with number Of Particles
  501. * @param {Number} numberOfParticles
  502. * @return {Boolean}
  503. */
  504. initWithTotalParticles:function (numberOfParticles) {
  505. if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
  506. // duration
  507. this.setDuration(cc.ParticleSystem.DURATION_INFINITY);
  508. // Gravity Mode
  509. this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
  510. // Gravity Mode: gravity
  511. this.setGravity(cc.p(0, 0));
  512. // Gravity Mode: speed of particles
  513. this.setSpeed(150);
  514. this.setSpeedVar(0);
  515. // Gravity Mode: radial
  516. this.setRadialAccel(-380);
  517. this.setRadialAccelVar(0);
  518. // Gravity Mode: tangential
  519. this.setTangentialAccel(45);
  520. this.setTangentialAccelVar(0);
  521. // angle
  522. this.setAngle(90);
  523. this.setAngleVar(0);
  524. // emitter position
  525. var winSize = cc.director.getWinSize();
  526. this.setPosition(winSize.width / 2, winSize.height / 2);
  527. this.setPosVar(cc.p(0,0));
  528. // life of particles
  529. this.setLife(12);
  530. this.setLifeVar(0);
  531. // size, in pixels
  532. this.setStartSize(20.0);
  533. this.setStartSizeVar(0.0);
  534. this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
  535. // emits per second
  536. this.setEmissionRate(this.getTotalParticles() / this.getLife());
  537. // color of particles
  538. this.setStartColor(cc.color(128,128,128,255));
  539. this.setStartColorVar(cc.color(128,128,128,0));
  540. this.setEndColor(cc.color(128,128,128,255));
  541. this.setEndColorVar(cc.color(128,128,128,0));
  542. // additive
  543. this.setBlendAdditive(false);
  544. return true;
  545. }
  546. return false;
  547. }
  548. });
  549. /**
  550. * Create a spiral particle system
  551. * @deprecated since v3.0 please use new cc.ParticleSpiral() instead.
  552. * @return {cc.ParticleSpiral}
  553. *
  554. * @example
  555. * var emitter = cc.ParticleSpiral.create();
  556. */
  557. cc.ParticleSpiral.create = function () {
  558. return new cc.ParticleSpiral();
  559. };
  560. /**
  561. * An explosion particle system
  562. * @class
  563. * @extends cc.ParticleSystem
  564. *
  565. * @example
  566. * var emitter = new cc.ParticleExplosion();
  567. */
  568. cc.ParticleExplosion = cc.ParticleSystem.extend(/** @lends cc.ParticleExplosion# */{
  569. /**
  570. * <p>The cc.ParticleExplosion's constructor. <br/>
  571. * This function will automatically be invoked when you create a node using new construction: "var node = new cc.ParticleExplosion()".<br/>
  572. * Override it to extend its behavior, remember to call "this._super()" in the extended "ctor" function.</p>
  573. */
  574. ctor:function () {
  575. cc.ParticleSystem.prototype.ctor.call(this, (cc._renderType === cc._RENDER_TYPE_WEBGL) ? 700 : 300);
  576. },
  577. /**
  578. * initialize an explosion particle system with number Of Particles
  579. * @param {Number} numberOfParticles
  580. * @return {Boolean}
  581. */
  582. initWithTotalParticles:function (numberOfParticles) {
  583. if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
  584. // duration
  585. this.setDuration(0.1);
  586. this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
  587. // Gravity Mode: gravity
  588. this.setGravity(cc.p(0, 0));
  589. // Gravity Mode: speed of particles
  590. this.setSpeed(70);
  591. this.setSpeedVar(40);
  592. // Gravity Mode: radial
  593. this.setRadialAccel(0);
  594. this.setRadialAccelVar(0);
  595. // Gravity Mode: tangential
  596. this.setTangentialAccel(0);
  597. this.setTangentialAccelVar(0);
  598. // angle
  599. this.setAngle(90);
  600. this.setAngleVar(360);
  601. // emitter position
  602. var winSize = cc.director.getWinSize();
  603. this.setPosition(winSize.width / 2, winSize.height / 2);
  604. this.setPosVar(cc.p(0,0));
  605. // life of particles
  606. this.setLife(5.0);
  607. this.setLifeVar(2);
  608. // size, in pixels
  609. this.setStartSize(15.0);
  610. this.setStartSizeVar(10.0);
  611. this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
  612. // emits per second
  613. this.setEmissionRate(this.getTotalParticles() / this.getDuration());
  614. // color of particles
  615. this.setStartColor(cc.color(179, 26, 51, 255));
  616. this.setStartColorVar(cc.color(128, 128, 128, 0));
  617. this.setEndColor(cc.color(128, 128, 128, 0));
  618. this.setEndColorVar(cc.color(128, 128, 128, 0));
  619. // additive
  620. this.setBlendAdditive(false);
  621. return true;
  622. }
  623. return false;
  624. }
  625. });
  626. /**
  627. * Create an explosion particle system
  628. * @deprecated since v3.0 please use new cc.ParticleExplosion() instead.
  629. * @return {cc.ParticleExplosion}
  630. *
  631. * @example
  632. * var emitter = cc.ParticleExplosion.create();
  633. */
  634. cc.ParticleExplosion.create = function () {
  635. return new cc.ParticleExplosion();
  636. };
  637. /**
  638. * A smoke particle system
  639. * @class
  640. * @extends cc.ParticleSystem
  641. *
  642. * @example
  643. * var emitter = new cc.ParticleSmoke();
  644. */
  645. cc.ParticleSmoke = cc.ParticleSystem.extend(/** @lends cc.ParticleSmoke# */{
  646. /**
  647. * <p>The cc.ParticleSmoke's constructor. <br/>
  648. * This function will automatically be invoked when you create a node using new construction: "var node = new cc.ParticleSmoke()".<br/>
  649. * Override it to extend its behavior, remember to call "this._super()" in the extended "ctor" function.</p>
  650. */
  651. ctor:function () {
  652. cc.ParticleSystem.prototype.ctor.call(this, (cc._renderType === cc._RENDER_TYPE_WEBGL) ? 200 : 100);
  653. },
  654. /**
  655. * initialize a smoke particle system with number Of Particles
  656. * @param {Number} numberOfParticles
  657. * @return {Boolean}
  658. */
  659. initWithTotalParticles:function (numberOfParticles) {
  660. if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
  661. // duration
  662. this.setDuration(cc.ParticleSystem.DURATION_INFINITY);
  663. // Emitter mode: Gravity Mode
  664. this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
  665. // Gravity Mode: gravity
  666. this.setGravity(cc.p(0, 0));
  667. // Gravity Mode: radial acceleration
  668. this.setRadialAccel(0);
  669. this.setRadialAccelVar(0);
  670. // Gravity Mode: speed of particles
  671. this.setSpeed(25);
  672. this.setSpeedVar(10);
  673. // angle
  674. this.setAngle(90);
  675. this.setAngleVar(5);
  676. // emitter position
  677. var winSize = cc.director.getWinSize();
  678. this.setPosition(winSize.width / 2, 0);
  679. this.setPosVar(cc.p(20, 0));
  680. // life of particles
  681. this.setLife(4);
  682. this.setLifeVar(1);
  683. // size, in pixels
  684. this.setStartSize(60.0);
  685. this.setStartSizeVar(10.0);
  686. this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
  687. // emits per frame
  688. this.setEmissionRate(this.getTotalParticles() / this.getLife());
  689. // color of particles
  690. this.setStartColor(cc.color(204, 204, 204, 255));
  691. this.setStartColorVar(cc.color(5, 5, 5, 0));
  692. this.setEndColor(cc.color(0, 0, 0, 255));
  693. this.setEndColorVar(cc.color(0, 0, 0, 0));
  694. // additive
  695. this.setBlendAdditive(false);
  696. return true;
  697. }
  698. return false;
  699. }
  700. });
  701. /**
  702. * Create a smoke particle system
  703. * @deprecated since v3.0 please use new cc.ParticleSmoke() instead.
  704. * @return {cc.ParticleSmoke}
  705. *
  706. * @example
  707. * var emitter = cc.ParticleFireworks.create();
  708. */
  709. cc.ParticleSmoke.create = function () {
  710. return new cc.ParticleSmoke();
  711. };
  712. /**
  713. * A snow particle system
  714. * @class
  715. * @extends cc.ParticleSystem
  716. *
  717. * @example
  718. * var emitter = new cc.ParticleSnow();
  719. */
  720. cc.ParticleSnow = cc.ParticleSystem.extend(/** @lends cc.ParticleSnow# */{
  721. /**
  722. * <p>The cc.ParticleSnow's constructor. <br/>
  723. * This function will automatically be invoked when you create a node using new construction: "var node = new cc.ParticleSnow()".<br/>
  724. * Override it to extend its behavior, remember to call "this._super()" in the extended "ctor" function.</p>
  725. */
  726. ctor:function () {
  727. cc.ParticleSystem.prototype.ctor.call(this, (cc._renderType === cc._RENDER_TYPE_WEBGL) ? 700 : 250);
  728. },
  729. /**
  730. * initialize a snow particle system with number Of Particles
  731. * @param {Number} numberOfParticles
  732. * @return {Boolean}
  733. */
  734. initWithTotalParticles:function (numberOfParticles) {
  735. if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
  736. // duration
  737. this.setDuration(cc.ParticleSystem.DURATION_INFINITY);
  738. // set gravity mode.
  739. this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
  740. // Gravity Mode: gravity
  741. this.setGravity(cc.p(0, -1));
  742. // Gravity Mode: speed of particles
  743. this.setSpeed(5);
  744. this.setSpeedVar(1);
  745. // Gravity Mode: radial
  746. this.setRadialAccel(0);
  747. this.setRadialAccelVar(1);
  748. // Gravity mode: tangential
  749. this.setTangentialAccel(0);
  750. this.setTangentialAccelVar(1);
  751. // emitter position
  752. var winSize = cc.director.getWinSize();
  753. this.setPosition(winSize.width / 2, winSize.height + 10);
  754. this.setPosVar(cc.p(winSize.width / 2, 0));
  755. // angle
  756. this.setAngle(-90);
  757. this.setAngleVar(5);
  758. // life of particles
  759. this.setLife(45);
  760. this.setLifeVar(15);
  761. // size, in pixels
  762. this.setStartSize(10.0);
  763. this.setStartSizeVar(5.0);
  764. this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
  765. // emits per second
  766. this.setEmissionRate(10);
  767. // color of particles
  768. this.setStartColor(cc.color(255, 255, 255, 255));
  769. this.setStartColorVar(cc.color(0, 0, 0, 0));
  770. this.setEndColor(cc.color(255, 255, 255, 0));
  771. this.setEndColorVar(cc.color(0, 0, 0, 0));
  772. // additive
  773. this.setBlendAdditive(false);
  774. return true;
  775. }
  776. return false;
  777. }
  778. });
  779. /**
  780. * Create a snow particle system
  781. * @deprecated since v3.0 please use new cc.ParticleSnow() instead.
  782. * @return {cc.ParticleSnow}
  783. *
  784. * @example
  785. * var emitter = cc.ParticleSnow.create();
  786. */
  787. cc.ParticleSnow.create = function () {
  788. return new cc.ParticleSnow();
  789. };
  790. //! @brief A rain particle system
  791. /**
  792. * A rain particle system
  793. * @class
  794. * @extends cc.ParticleSystem
  795. *
  796. * @example
  797. * var emitter = new cc.ParticleRain();
  798. */
  799. cc.ParticleRain = cc.ParticleSystem.extend(/** @lends cc.ParticleRain# */{
  800. /**
  801. * <p>The cc.ParticleRain's constructor. <br/>
  802. * This function will automatically be invoked when you create a node using new construction: "var node = new cc.ParticleRain()".<br/>
  803. * Override it to extend its behavior, remember to call "this._super()" in the extended "ctor" function.</p>
  804. */
  805. ctor:function () {
  806. cc.ParticleSystem.prototype.ctor.call(this, (cc._renderType === cc._RENDER_TYPE_WEBGL) ? 1000 : 300);
  807. },
  808. /**
  809. * initialize a rain particle system with number Of Particles
  810. * @param {Number} numberOfParticles
  811. * @return {Boolean}
  812. */
  813. initWithTotalParticles:function (numberOfParticles) {
  814. if (cc.ParticleSystem.prototype.initWithTotalParticles.call(this, numberOfParticles)) {
  815. // duration
  816. this.setDuration(cc.ParticleSystem.DURATION_INFINITY);
  817. this.setEmitterMode(cc.ParticleSystem.MODE_GRAVITY);
  818. // Gravity Mode: gravity
  819. this.setGravity(cc.p(10, -10));
  820. // Gravity Mode: radial
  821. this.setRadialAccel(0);
  822. this.setRadialAccelVar(1);
  823. // Gravity Mode: tangential
  824. this.setTangentialAccel(0);
  825. this.setTangentialAccelVar(1);
  826. // Gravity Mode: speed of particles
  827. this.setSpeed(130);
  828. this.setSpeedVar(30);
  829. // angle
  830. this.setAngle(-90);
  831. this.setAngleVar(5);
  832. // emitter position
  833. var winSize = cc.director.getWinSize();
  834. this.setPosition(winSize.width / 2, winSize.height);
  835. this.setPosVar(cc.p(winSize.width / 2, 0));
  836. // life of particles
  837. this.setLife(4.5);
  838. this.setLifeVar(0);
  839. // size, in pixels
  840. this.setStartSize(4.0);
  841. this.setStartSizeVar(2.0);
  842. this.setEndSize(cc.ParticleSystem.START_SIZE_EQUAL_TO_END_SIZE);
  843. // emits per second
  844. this.setEmissionRate(20);
  845. // color of particles
  846. this.setStartColor(cc.color(179, 204, 255, 255));
  847. this.setStartColorVar(cc.color(0, 0, 0, 0));
  848. this.setEndColor(cc.color(179, 204, 255, 128));
  849. this.setEndColorVar(cc.color(0, 0, 0, 0));
  850. // additive
  851. this.setBlendAdditive(false);
  852. return true;
  853. }
  854. return false;
  855. }
  856. });
  857. /**
  858. * Create a rain particle system
  859. * @deprecated since v3.0 please use cc.ParticleRain() instead.
  860. * @return {cc.ParticleRain}
  861. *
  862. * @example
  863. * var emitter = cc.ParticleRain.create();
  864. */
  865. cc.ParticleRain.create = function () {
  866. return new cc.ParticleRain();
  867. };