CCParticleExamples.js 30 KB

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