CCActionTiledGrid.js 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  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. * cc.ShakyTiles3D action. <br />
  24. * Reference the test cases (Effects Test)
  25. * @class
  26. * @extends cc.TiledGrid3DAction
  27. * @param {Number} duration
  28. * @param {cc.Size} gridSize
  29. * @param {Number} range
  30. * @param {Boolean} shakeZ
  31. */
  32. cc.ShakyTiles3D = cc.TiledGrid3DAction.extend(/** @lends cc.ShakyTiles3D# */{
  33. _randRange:0,
  34. _shakeZ:false,
  35. /**
  36. * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br />
  37. * Creates the action with a range, whether or not to shake Z vertices, a grid size, and duration.
  38. * @param {Number} duration
  39. * @param {cc.Size} gridSize
  40. * @param {Number} range
  41. * @param {Boolean} shakeZ
  42. */
  43. ctor:function (duration, gridSize, range, shakeZ) {
  44. cc.GridAction.prototype.ctor.call(this);
  45. shakeZ !== undefined && this.initWithDuration(duration, gridSize, range, shakeZ);
  46. },
  47. /**
  48. * Initializes the action with a range, whether or not to shake Z vertices, a grid size, and duration.
  49. * @param {Number} duration
  50. * @param {cc.Size} gridSize
  51. * @param {Number} range
  52. * @param {Boolean} shakeZ
  53. * @return {Boolean}
  54. */
  55. initWithDuration:function (duration, gridSize, range, shakeZ) {
  56. if (cc.TiledGrid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) {
  57. this._randRange = range;
  58. this._shakeZ = shakeZ;
  59. return true;
  60. }
  61. return false;
  62. },
  63. /**
  64. * Called once per frame. Time is the number of seconds of a frame interval. <br />
  65. * @param {Number} dt
  66. */
  67. update:function (dt) {
  68. var locGridSize = this._gridSize, locRandRange = this._randRange;
  69. var locPos = cc.p(0, 0);
  70. for (var i = 0; i < locGridSize.width; ++i) {
  71. for (var j = 0; j < locGridSize.height; ++j) {
  72. locPos.x = i;
  73. locPos.y = j;
  74. var coords = this.originalTile(locPos);
  75. // X
  76. coords.bl.x += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  77. coords.br.x += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  78. coords.tl.x += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  79. coords.tr.x += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  80. // Y
  81. coords.bl.y += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  82. coords.br.y += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  83. coords.tl.y += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  84. coords.tr.y += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  85. if (this._shakeZ) {
  86. coords.bl.z += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  87. coords.br.z += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  88. coords.tl.z += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  89. coords.tr.z += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  90. }
  91. this.setTile(locPos, coords);
  92. }
  93. }
  94. }
  95. });
  96. /**
  97. * Creates the action with a range, whether or not to shake Z vertices, a grid size, and duration. <br />
  98. * Reference the test cases (Effects Test)
  99. * @function
  100. * @param {Number} duration
  101. * @param {cc.Size} gridSize
  102. * @param {Number} range
  103. * @param {Boolean} shakeZ
  104. * @return {cc.ShakyTiles3D}
  105. */
  106. cc.shakyTiles3D = function (duration, gridSize, range, shakeZ) {
  107. return new cc.ShakyTiles3D(duration, gridSize, range, shakeZ);
  108. };
  109. /**
  110. * Please use cc.shakyTiles3D instead. <br />
  111. * creates the action with a range, whether or not to shake Z vertices, a grid size, and duration. <br />
  112. * Reference the test cases (Effects Test)
  113. * @param {Number} duration
  114. * @param {cc.Size} gridSize
  115. * @param {Number} range
  116. * @param {Boolean} shakeZ
  117. * @return {cc.ShakyTiles3D}
  118. * @static
  119. * @deprecated since v3.0 <br /> Please use cc.shakyTiles3D instead.
  120. */
  121. cc.ShakyTiles3D.create = cc.shakyTiles3D;
  122. /**
  123. * cc.ShatteredTiles3D action. <br />
  124. * Reference the test cases (Effects Test)
  125. * @class
  126. * @extends cc.TiledGrid3DAction
  127. * @param {Number} duration
  128. * @param {cc.Size} gridSize
  129. * @param {Number} range
  130. * @param {Boolean} shatterZ
  131. */
  132. cc.ShatteredTiles3D = cc.TiledGrid3DAction.extend(/** @lends cc.ShatteredTiles3D# */{
  133. _randRange:0,
  134. _once:false,
  135. _shatterZ:false,
  136. /**
  137. * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br />
  138. * Creates the action with a range, whether of not to shatter Z vertices, a grid size and duration.
  139. * @param {Number} duration
  140. * @param {cc.Size} gridSize
  141. * @param {Number} range
  142. * @param {Boolean} shatterZ
  143. */
  144. ctor:function (duration, gridSize, range, shatterZ) {
  145. cc.GridAction.prototype.ctor.call(this);
  146. shatterZ !== undefined && this.initWithDuration(duration, gridSize, range, shatterZ);
  147. },
  148. /**
  149. * Initializes the action with a range, whether or not to shatter Z vertices, a grid size and duration. <br />
  150. * @param {Number} duration
  151. * @param {cc.Size} gridSize
  152. * @param {Number} range
  153. * @param {Boolean} shatterZ
  154. * @return {Boolean}
  155. */
  156. initWithDuration:function (duration, gridSize, range, shatterZ) {
  157. if (cc.TiledGrid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) {
  158. this._once = false;
  159. this._randRange = range;
  160. this._shatterZ = shatterZ;
  161. return true;
  162. }
  163. return false;
  164. },
  165. /**
  166. * Called once per frame. Time is the number of seconds of a frame interval. <br />
  167. * @param {Number} dt
  168. */
  169. update:function (dt) {
  170. if (this._once === false) {
  171. var locGridSize = this._gridSize, locRandRange = this._randRange;
  172. var coords, locPos = cc.p(0, 0);
  173. for (var i = 0; i < locGridSize.width; ++i) {
  174. for (var j = 0; j < locGridSize.height; ++j) {
  175. locPos.x = i;
  176. locPos.y = j;
  177. coords = this.originalTile(locPos);
  178. // X
  179. coords.bl.x += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  180. coords.br.x += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  181. coords.tl.x += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  182. coords.tr.x += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  183. // Y
  184. coords.bl.y += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  185. coords.br.y += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  186. coords.tl.y += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  187. coords.tr.y += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  188. if (this._shatterZ) {
  189. coords.bl.z += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  190. coords.br.z += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  191. coords.tl.z += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  192. coords.tr.z += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
  193. }
  194. this.setTile(locPos, coords);
  195. }
  196. }
  197. this._once = true;
  198. }
  199. }
  200. });
  201. /**
  202. * Creates the action with a range, whether of not to shatter Z vertices, a grid size and duration. <br />
  203. * Reference the test cases (Effects Test)
  204. * @function
  205. * @param {Number} duration
  206. * @param {cc.Size} gridSize
  207. * @param {Number} range
  208. * @param {Boolean} shatterZ
  209. * @return {cc.ShatteredTiles3D}
  210. */
  211. cc.shatteredTiles3D = function (duration, gridSize, range, shatterZ) {
  212. return new cc.ShatteredTiles3D(duration, gridSize, range, shatterZ);
  213. };
  214. /**
  215. * Please use cc.shatteredTiles3D instead. <br />
  216. * Creates the action with a range, whether of not to shatter Z vertices, a grid size and duration. <br />
  217. * Reference the test cases (Effects Test)
  218. * @param {Number} duration
  219. * @param {cc.Size} gridSize
  220. * @param {Number} range
  221. * @param {Boolean} shatterZ
  222. * @return {cc.ShatteredTiles3D}
  223. * @static
  224. * @deprecated since v3.0 <br /> Please use cc.shatteredTiles3D instead.
  225. */
  226. cc.ShatteredTiles3D.create = cc.shatteredTiles3D;
  227. /**
  228. * A Tile composed of position, startPosition and delta.
  229. * @Class
  230. * @constructor
  231. * @param {cc.Point} [position=cc.p(0,0)]
  232. * @param {cc.Point} [startPosition=cc.p(0,0)]
  233. * @param {cc.Size} [delta=cc.p(0,0)]
  234. */
  235. cc.Tile = function (position, startPosition, delta) {
  236. this.position = position || cc.p(0,0);
  237. this.startPosition = startPosition || cc.p(0,0);
  238. this.delta = delta || cc.p(0,0);
  239. };
  240. /**
  241. * cc.ShuffleTiles action, Shuffle the tiles in random order. <br />
  242. * Reference the test cases (Effects Test)
  243. * @class
  244. * @extends cc.TiledGrid3DAction
  245. * @param {Number} duration
  246. * @param {cc.Size} gridSize
  247. * @param {Number} seed
  248. */
  249. cc.ShuffleTiles = cc.TiledGrid3DAction.extend(/** @lends cc.ShuffleTiles# */{
  250. _seed:0,
  251. _tilesCount:0,
  252. _tilesOrder:null,
  253. _tiles:null,
  254. /**
  255. * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br />
  256. * Creates the action with a random seed, the grid size and the duration.
  257. * @param {Number} duration
  258. * @param {cc.Size} gridSize
  259. * @param {Number} seed
  260. */
  261. ctor:function (duration, gridSize, seed) {
  262. cc.GridAction.prototype.ctor.call(this);
  263. this._tilesOrder = [];
  264. this._tiles = [];
  265. seed !== undefined && this.initWithDuration(duration, gridSize, seed);
  266. },
  267. /**
  268. * Initializes the action with a random seed, the grid size and the duration.
  269. * @param {Number} duration
  270. * @param {cc.Size} gridSize
  271. * @param {Number} seed
  272. * @return {Boolean}
  273. */
  274. initWithDuration:function (duration, gridSize, seed) {
  275. if (cc.TiledGrid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) {
  276. this._seed = seed;
  277. this._tilesOrder.length = 0;
  278. this._tiles.length = 0;
  279. return true;
  280. }
  281. return false;
  282. },
  283. /**
  284. * Shuffle
  285. * @param {Array} array
  286. * @param {Number} len
  287. */
  288. shuffle:function (array, len) {
  289. for (var i = len - 1; i >= 0; i--) {
  290. var j = 0 | (cc.rand() % (i + 1));
  291. var v = array[i];
  292. array[i] = array[j];
  293. array[j] = v;
  294. }
  295. },
  296. /**
  297. * Get Delta
  298. * @param {cc.Size} pos
  299. */
  300. getDelta:function (pos) {
  301. var locGridSize = this._gridSize;
  302. var idx = pos.width * locGridSize.height + pos.height;
  303. return cc.size(((this._tilesOrder[idx] / locGridSize.height) - pos.width),
  304. ((this._tilesOrder[idx] % locGridSize.height) - pos.height));
  305. },
  306. /**
  307. * Place Tile
  308. * @param {cc.Point} pos
  309. * @param {cc.Tile} tile
  310. */
  311. placeTile:function (pos, tile) {
  312. var coords = this.originalTile(pos);
  313. var step = this.target.grid.getStep();
  314. var locPosition = tile.position;
  315. coords.bl.x += (locPosition.x * step.x);
  316. coords.bl.y += (locPosition.y * step.y);
  317. coords.br.x += (locPosition.x * step.x);
  318. coords.br.y += (locPosition.y * step.y);
  319. coords.tl.x += (locPosition.x * step.x);
  320. coords.tl.y += (locPosition.y * step.y);
  321. coords.tr.x += (locPosition.x * step.x);
  322. coords.tr.y += (locPosition.y * step.y);
  323. this.setTile(pos, coords);
  324. },
  325. /**
  326. * Start with target
  327. * @param {cc.Node} target
  328. */
  329. startWithTarget:function (target) {
  330. cc.TiledGrid3DAction.prototype.startWithTarget.call(this, target);
  331. var locGridSize = this._gridSize;
  332. this._tilesCount = locGridSize.width * locGridSize.height;
  333. var locTilesOrder = this._tilesOrder;
  334. locTilesOrder.length = 0;
  335. /**
  336. * Use k to loop. Because m_nTilesCount is unsigned int,
  337. * and i is used later for int.
  338. */
  339. for (var k = 0; k < this._tilesCount; ++k)
  340. locTilesOrder[k] = k;
  341. this.shuffle(locTilesOrder, this._tilesCount);
  342. var locTiles = this._tiles ;
  343. locTiles.length = 0;
  344. var tileIndex = 0, tempSize = cc.size(0,0);
  345. for (var i = 0; i < locGridSize.width; ++i) {
  346. for (var j = 0; j < locGridSize.height; ++j) {
  347. locTiles[tileIndex] = new cc.Tile();
  348. locTiles[tileIndex].position = cc.p(i, j);
  349. locTiles[tileIndex].startPosition = cc.p(i, j);
  350. tempSize.width = i;
  351. tempSize.height = j;
  352. locTiles[tileIndex].delta = this.getDelta(tempSize);
  353. ++tileIndex;
  354. }
  355. }
  356. },
  357. /**
  358. * Called once per frame. Time is the number of seconds of a frame interval.
  359. * @param {Number} dt
  360. */
  361. update:function (dt) {
  362. var tileIndex = 0, locGridSize = this._gridSize, locTiles = this._tiles;
  363. var selTile, locPos = cc.p(0, 0);
  364. for (var i = 0; i < locGridSize.width; ++i) {
  365. for (var j = 0; j < locGridSize.height; ++j) {
  366. locPos.x = i;
  367. locPos.y = j;
  368. selTile = locTiles[tileIndex];
  369. selTile.position.x = selTile.delta.width * dt;
  370. selTile.position.y = selTile.delta.height * dt;
  371. this.placeTile(locPos, selTile);
  372. ++tileIndex;
  373. }
  374. }
  375. }
  376. });
  377. /**
  378. * Creates the action with a random seed, the grid size and the duration. <br />
  379. * Reference the test cases (Effects Test)
  380. * @function
  381. * @param {Number} duration
  382. * @param {cc.Size} gridSize
  383. * @param {Number} seed
  384. * @return {cc.ShuffleTiles}
  385. */
  386. cc.shuffleTiles = function (duration, gridSize, seed) {
  387. return new cc.ShuffleTiles(duration, gridSize, seed);
  388. };
  389. /**
  390. * Please use cc.shuffleTiles instead. <br />
  391. * Creates the action with a random seed, the grid size and the duration. <br />
  392. * Reference the test cases (Effects Test)
  393. * @param {Number} duration
  394. * @param {cc.Size} gridSize
  395. * @param {Number} seed
  396. * @return {cc.ShuffleTiles}
  397. * @static
  398. * @deprecated since v3.0 <br /> Please use cc.shuffleTiles instead.
  399. */
  400. cc.ShuffleTiles.create = cc.shuffleTiles;
  401. /**
  402. * cc.FadeOutTRTiles action. Fades out the tiles in a Top-Right direction. <br />
  403. * Reference the test cases (Effects Test)
  404. * @class
  405. * @extends cc.TiledGrid3DAction
  406. */
  407. cc.FadeOutTRTiles = cc.TiledGrid3DAction.extend(/** @lends cc.FadeOutTRTiles# */{
  408. /**
  409. * Test function
  410. * @param {cc.Size} pos
  411. * @param {Number} time
  412. */
  413. testFunc:function (pos, time) {
  414. var locX = this._gridSize.width * time;
  415. var locY = this._gridSize.height * time;
  416. if ((locX + locY) == 0.0)
  417. return 1.0;
  418. return Math.pow((pos.width + pos.height) / (locX + locY), 6);
  419. },
  420. /**
  421. * Turn on Tile
  422. * @param {cc.Point} pos
  423. */
  424. turnOnTile:function (pos) {
  425. this.setTile(pos, this.originalTile(pos));
  426. },
  427. /**
  428. * Turn Off Tile
  429. * @param {cc.Point} pos
  430. */
  431. turnOffTile:function (pos) {
  432. this.setTile(pos, new cc.Quad3());
  433. },
  434. /**
  435. * Transform tile
  436. * @param {cc.Point} pos
  437. * @param {Number} distance
  438. */
  439. transformTile:function (pos, distance) {
  440. var coords = this.originalTile(pos);
  441. var step = this.target.grid.getStep();
  442. coords.bl.x += (step.x / 2) * (1.0 - distance);
  443. coords.bl.y += (step.y / 2) * (1.0 - distance);
  444. coords.br.x -= (step.x / 2) * (1.0 - distance);
  445. coords.br.y += (step.y / 2) * (1.0 - distance);
  446. coords.tl.x += (step.x / 2) * (1.0 - distance);
  447. coords.tl.y -= (step.y / 2) * (1.0 - distance);
  448. coords.tr.x -= (step.x / 2) * (1.0 - distance);
  449. coords.tr.y -= (step.y / 2) * (1.0 - distance);
  450. this.setTile(pos, coords);
  451. },
  452. /**
  453. * Called once per frame. Time is the number of seconds of a frame interval.
  454. * @param {Number} dt
  455. */
  456. update:function (dt) {
  457. var locGridSize = this._gridSize;
  458. var locPos = cc.p(0, 0), locSize = cc.size(0, 0), distance;
  459. for (var i = 0; i < locGridSize.width; ++i) {
  460. for (var j = 0; j < locGridSize.height; ++j) {
  461. locPos.x = i;
  462. locPos.y = j;
  463. locSize.width = i;
  464. locSize.height = j;
  465. distance = this.testFunc(locSize, dt);
  466. if (distance == 0)
  467. this.turnOffTile(locPos);
  468. else if (distance < 1)
  469. this.transformTile(locPos, distance);
  470. else
  471. this.turnOnTile(locPos);
  472. }
  473. }
  474. }
  475. });
  476. /**
  477. * Creates the action with the grid size and the duration. <br />
  478. * Reference the test cases (Effects Test)
  479. * @function
  480. * @param duration
  481. * @param gridSize
  482. * @return {cc.FadeOutTRTiles}
  483. */
  484. cc.fadeOutTRTiles = function (duration, gridSize) {
  485. return new cc.FadeOutTRTiles(duration, gridSize);
  486. };
  487. /**
  488. * Please use cc.fadeOutTRTiles instead. <br />
  489. * Creates the action with the grid size and the duration. <br />
  490. * Reference the test cases (Effects Test)
  491. * @param duration
  492. * @param gridSize
  493. * @return {cc.FadeOutTRTiles}
  494. * @static
  495. * @deprecated since v3.0 <br /> Please use cc.fadeOutTRTiles instead.
  496. */
  497. cc.FadeOutTRTiles.create = cc.fadeOutTRTiles;
  498. /**
  499. * cc.FadeOutBLTiles action. Fades out the tiles in a Bottom-Left direction. <br />
  500. * Reference the test cases (Effects Test)
  501. * @class
  502. * @extends cc.FadeOutTRTiles
  503. */
  504. cc.FadeOutBLTiles = cc.FadeOutTRTiles.extend(/** @lends cc.FadeOutBLTiles# */{
  505. /**
  506. * Test function
  507. * @param {cc.Size} pos
  508. * @param {Number} time
  509. */
  510. testFunc:function (pos, time) {
  511. var locX = this._gridSize.width * (1.0 - time);
  512. var locY = this._gridSize.height * (1.0 - time);
  513. if ((pos.width + pos.height) == 0)
  514. return 1.0;
  515. return Math.pow((locX + locY) / (pos.width + pos.height), 6);
  516. }
  517. });
  518. /**
  519. * Creates the action with the grid size and the duration. <br />
  520. * Reference the test cases (Effects Test)
  521. * @function
  522. * @param duration
  523. * @param gridSize
  524. * @return {cc.FadeOutBLTiles}
  525. */
  526. cc.fadeOutBLTiles = function (duration, gridSize) {
  527. return new cc.FadeOutBLTiles(duration, gridSize);
  528. };
  529. /**
  530. * Please use cc.fadeOutBLTiles instead. <br />
  531. * Creates the action with the grid size and the duration. <br />
  532. * Reference the test cases (Effects Test)
  533. * @param duration
  534. * @param gridSize
  535. * @return {cc.FadeOutBLTiles}
  536. * @static
  537. * @deprecated since v3.0 <br /> Please use cc.fadeOutBLTiles instead.
  538. */
  539. cc.FadeOutBLTiles.create = cc.fadeOutBLTiles;
  540. /**
  541. * cc.FadeOutUpTiles action. Fades out the tiles in upwards direction. <br />
  542. * Reference the test cases (Effects Test)
  543. * @class
  544. * @extends cc.FadeOutTRTiles
  545. */
  546. cc.FadeOutUpTiles = cc.FadeOutTRTiles.extend(/** @lends cc.FadeOutUpTiles# */{
  547. testFunc:function (pos, time) {
  548. var locY = this._gridSize.height * time;
  549. if (locY == 0.0)
  550. return 1.0;
  551. return Math.pow(pos.height / locY, 6);
  552. },
  553. transformTile:function (pos, distance) {
  554. var coords = this.originalTile(pos);
  555. var step = this.target.grid.getStep();
  556. coords.bl.y += (step.y / 2) * (1.0 - distance);
  557. coords.br.y += (step.y / 2) * (1.0 - distance);
  558. coords.tl.y -= (step.y / 2) * (1.0 - distance);
  559. coords.tr.y -= (step.y / 2) * (1.0 - distance);
  560. this.setTile(pos, coords);
  561. }
  562. });
  563. /**
  564. * Creates the action with the grid size and the duration. <br />
  565. * Reference the test cases (Effects Test)
  566. * @function
  567. * @param {Number} duration
  568. * @param {cc.Size} gridSize
  569. * @return {cc.FadeOutUpTiles}
  570. */
  571. cc.fadeOutUpTiles = function (duration, gridSize) {
  572. return new cc.FadeOutUpTiles(duration, gridSize);
  573. };
  574. /**
  575. * Please use cc.fadeOutUpTiles instead. <br />
  576. * Creates the action with the grid size and the duration. <br />
  577. * Reference the test cases (Effects Test)
  578. * @param {Number} duration
  579. * @param {cc.Size} gridSize
  580. * @return {cc.FadeOutUpTiles}
  581. * @static
  582. * @deprecated since v3.0 <br /> Please use cc.fadeOutUpTiles instead.
  583. */
  584. cc.FadeOutUpTiles.create = cc.fadeOutUpTiles;
  585. /**
  586. * cc.FadeOutDownTiles action. Fades out the tiles in downwards direction. <br />
  587. * Reference the test cases (Effects Test)
  588. * @class
  589. * @extends cc.FadeOutUpTiles
  590. */
  591. cc.FadeOutDownTiles = cc.FadeOutUpTiles.extend(/** @lends cc.FadeOutDownTiles# */{
  592. testFunc:function (pos, time) {
  593. var locY = this._gridSize.height * (1.0 - time);
  594. if (pos.height == 0)
  595. return 1.0;
  596. return Math.pow(locY / pos.height, 6);
  597. }
  598. });
  599. /**
  600. * Creates the action with the grid size and the duration. <br />
  601. * Reference the test cases (Effects Test)
  602. * @function
  603. * @param {Number} duration
  604. * @param {cc.Size} gridSize
  605. * @return {cc.FadeOutDownTiles}
  606. */
  607. cc.fadeOutDownTiles = function (duration, gridSize) {
  608. return new cc.FadeOutDownTiles(duration, gridSize);
  609. };
  610. /**
  611. * Please use cc.fadeOutDownTiles instead. <br />
  612. * Creates the action with the grid size and the duration. <br />
  613. * Reference the test cases (Effects Test)
  614. * @param {Number} duration
  615. * @param {cc.Size} gridSize
  616. * @return {cc.FadeOutDownTiles}
  617. * @static
  618. * @deprecated since v3.0 <br /> Please use cc.fadeOutDownTiles instead.
  619. */
  620. cc.FadeOutDownTiles.create = cc.fadeOutDownTiles;
  621. /**
  622. * cc.TurnOffTiles action.<br/>
  623. * Turn off the files in random order. <br />
  624. * Reference the test cases (Effects Test)
  625. * @class
  626. * @extends cc.TiledGrid3DAction
  627. * @param {Number} duration
  628. * @param {cc.Size} gridSize
  629. * @param {Number|Null} [seed=0]
  630. * @example
  631. * // turnOffTiles without seed
  632. * var toff = new cc.TurnOffTiles(this._duration, cc.size(x, y));
  633. *
  634. * // turnOffTiles with seed
  635. * var toff = new cc.TurnOffTiles(this._duration, cc.size(x, y), 0);
  636. */
  637. cc.TurnOffTiles = cc.TiledGrid3DAction.extend(/** @lends cc.TurnOffTiles# */{
  638. _seed:null,
  639. _tilesCount:0,
  640. _tilesOrder:null,
  641. /**
  642. * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br />
  643. * Creates the action with a random seed, the grid size and the duration.
  644. * @param {Number} duration
  645. * @param {cc.Size} gridSize
  646. * @param {Number|Null} [seed=0]
  647. */
  648. ctor:function (duration, gridSize, seed) {
  649. cc.GridAction.prototype.ctor.call(this);
  650. this._tilesOrder = [];
  651. gridSize !== undefined && this.initWithDuration(duration, gridSize, seed);
  652. },
  653. /**
  654. * Initializes the action with a random seed, the grid size and the duration.
  655. * @param {Number} duration
  656. * @param {cc.Size} gridSize
  657. * @param {Number|Null} [seed=0]
  658. * @return {Boolean}
  659. */
  660. initWithDuration:function (duration, gridSize, seed) {
  661. if (cc.TiledGrid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) {
  662. this._seed = seed || 0;
  663. this._tilesOrder.length = 0;
  664. return true;
  665. }
  666. return false;
  667. },
  668. /**
  669. * Shuffle
  670. * @param {Array} array
  671. * @param {Number} len
  672. */
  673. shuffle:function (array, len) {
  674. for (var i = len - 1; i >= 0; i--) {
  675. var j = 0 | (cc.rand() % (i + 1));
  676. var v = array[i];
  677. array[i] = array[j];
  678. array[j] = v;
  679. }
  680. },
  681. /**
  682. * Turn on tile.
  683. * @param {cc.Point} pos
  684. */
  685. turnOnTile:function (pos) {
  686. this.setTile(pos, this.originalTile(pos));
  687. },
  688. /**
  689. * Turn off title.
  690. * @param {cc.Point} pos
  691. */
  692. turnOffTile:function (pos) {
  693. this.setTile(pos, new cc.Quad3());
  694. },
  695. /**
  696. * called before the action start. It will also set the target.
  697. * @param {cc.Node} target
  698. */
  699. startWithTarget:function (target) {
  700. cc.TiledGrid3DAction.prototype.startWithTarget.call(this, target);
  701. this._tilesCount = this._gridSize.width * this._gridSize.height;
  702. var locTilesOrder = this._tilesOrder;
  703. locTilesOrder.length = 0;
  704. for (var i = 0; i < this._tilesCount; ++i)
  705. locTilesOrder[i] = i;
  706. this.shuffle(locTilesOrder, this._tilesCount);
  707. },
  708. /**
  709. * Called once per frame. Time is the number of seconds of a frame interval.
  710. * @param {Number} dt
  711. */
  712. update:function (dt) {
  713. var l = 0 | (dt * this._tilesCount), locGridSize = this._gridSize;
  714. var t,tilePos = cc.p(0,0), locTilesOrder = this._tilesOrder;
  715. for (var i = 0; i < this._tilesCount; i++) {
  716. t = locTilesOrder[i];
  717. tilePos.x = 0 | (t / locGridSize.height);
  718. tilePos.y = t % (0 | locGridSize.height);
  719. if (i < l)
  720. this.turnOffTile(tilePos);
  721. else
  722. this.turnOnTile(tilePos);
  723. }
  724. }
  725. });
  726. /**
  727. * Creates the action with a random seed, the grid size and the duration. <br />
  728. * Reference the test cases (Effects Test)
  729. * @function
  730. * @param {Number} duration
  731. * @param {cc.Size} gridSize
  732. * @param {Number|Null} [seed=0]
  733. * @return {cc.TurnOffTiles}
  734. * @example
  735. * // example
  736. * // turnOffTiles without seed
  737. * var toff = cc.turnOffTiles(this._duration, cc.size(x, y));
  738. *
  739. * // turnOffTiles with seed
  740. * var toff = cc.turnOffTiles(this._duration, cc.size(x, y), 0);
  741. */
  742. cc.turnOffTiles = function (duration, gridSize, seed) {
  743. return new cc.TurnOffTiles(duration, gridSize, seed);
  744. };
  745. /**
  746. * Please use cc.turnOffTiles instead. <br />
  747. * Creates the action with a random seed, the grid size and the duration. <br />
  748. * Reference the test cases (Effects Test)
  749. * @param {Number} duration
  750. * @param {cc.Size} gridSize
  751. * @param {Number|Null} [seed=0]
  752. * @return {cc.TurnOffTiles}
  753. * @static
  754. * @deprecated since v3.0 <br /> Please use cc.turnOffTiles instead.
  755. */
  756. cc.TurnOffTiles.create = cc.turnOffTiles;
  757. /**
  758. * cc.WavesTiles3D action. <br />
  759. * Reference the test cases (Effects Test)
  760. * @class
  761. * @extends cc.TiledGrid3DAction
  762. * @param {Number} duration
  763. * @param {cc.Size} gridSize
  764. * @param {Number} waves
  765. * @param {Number} amplitude
  766. */
  767. cc.WavesTiles3D = cc.TiledGrid3DAction.extend(/** @lends cc.WavesTiles3D# */{
  768. _waves:0,
  769. _amplitude:0,
  770. _amplitudeRate:0,
  771. /**
  772. * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br />
  773. * creates the action with a number of waves, the waves amplitude, the grid size and the duration.
  774. * @param {Number} duration
  775. * @param {cc.Size} gridSize
  776. * @param {Number} waves
  777. * @param {Number} amplitude
  778. */
  779. ctor:function (duration, gridSize, waves, amplitude) {
  780. cc.GridAction.prototype.ctor.call(this);
  781. amplitude !== undefined && this.initWithDuration(duration, gridSize, waves, amplitude);
  782. },
  783. /**
  784. * get amplitude of waves
  785. * @return {Number}
  786. */
  787. getAmplitude:function () {
  788. return this._amplitude;
  789. },
  790. /**
  791. * set amplitude of waves
  792. * @param {Number} amplitude
  793. */
  794. setAmplitude:function (amplitude) {
  795. this._amplitude = amplitude;
  796. },
  797. /**
  798. * get amplitude rate of waves
  799. * @return {Number}
  800. */
  801. getAmplitudeRate:function () {
  802. return this._amplitudeRate;
  803. },
  804. /**
  805. * set amplitude rate of waves
  806. * @param {Number} amplitudeRate
  807. */
  808. setAmplitudeRate:function (amplitudeRate) {
  809. this._amplitudeRate = amplitudeRate;
  810. },
  811. /**
  812. * initializes the action with a number of waves, the waves amplitude, the grid size and the duration
  813. * @param {Number} duration
  814. * @param {cc.Size} gridSize
  815. * @param {Number} waves
  816. * @param {Number} amplitude
  817. * @return {Boolean}
  818. */
  819. initWithDuration:function (duration, gridSize, waves, amplitude) {
  820. if (cc.TiledGrid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) {
  821. this._waves = waves;
  822. this._amplitude = amplitude;
  823. this._amplitudeRate = 1.0;
  824. return true;
  825. }
  826. return false;
  827. },
  828. /**
  829. * Called once per frame. Time is the number of seconds of a frame interval.
  830. * @param {Number} dt
  831. */
  832. update:function (dt) {
  833. var locGridSize = this._gridSize, locWaves = this._waves, locAmplitude = this._amplitude, locAmplitudeRate = this._amplitudeRate;
  834. var locPos = cc.p(0, 0), coords;
  835. for (var i = 0; i < locGridSize.width; i++) {
  836. for (var j = 0; j < locGridSize.height; j++) {
  837. locPos.x = i;
  838. locPos.y = j;
  839. coords = this.originalTile(locPos);
  840. coords.bl.z = (Math.sin(dt * Math.PI * locWaves * 2 +
  841. (coords.bl.y + coords.bl.x) * 0.01) * locAmplitude * locAmplitudeRate);
  842. coords.br.z = coords.bl.z;
  843. coords.tl.z = coords.bl.z;
  844. coords.tr.z = coords.bl.z;
  845. this.setTile(locPos, coords);
  846. }
  847. }
  848. }
  849. });
  850. /**
  851. * creates the action with a number of waves, the waves amplitude, the grid size and the duration. <br />
  852. * Reference the test cases (Effects Test)
  853. * @function
  854. * @param {Number} duration
  855. * @param {cc.Size} gridSize
  856. * @param {Number} waves
  857. * @param {Number} amplitude
  858. * @return {cc.WavesTiles3D}
  859. */
  860. cc.wavesTiles3D = function (duration, gridSize, waves, amplitude) {
  861. return new cc.WavesTiles3D(duration, gridSize, waves, amplitude);
  862. };
  863. /**
  864. * Please use cc.wavesTiles3D instead
  865. * creates the action with a number of waves, the waves amplitude, the grid size and the duration. <br />
  866. * Reference the test cases (Effects Test)
  867. * @param {Number} duration
  868. * @param {cc.Size} gridSize
  869. * @param {Number} waves
  870. * @param {Number} amplitude
  871. * @return {cc.WavesTiles3D}
  872. * @static
  873. * @deprecated since v3.0 <br /> Please use cc.wavesTiles3D instead.
  874. */
  875. cc.WavesTiles3D.create = cc.wavesTiles3D;
  876. /**
  877. * cc.JumpTiles3D action. A sin function is executed to move the tiles across the Z axis. <br />
  878. * Reference the test cases (Effects Test)
  879. * @class
  880. * @extends cc.TiledGrid3DAction
  881. * @param {Number} duration
  882. * @param {cc.Size} gridSize
  883. * @param {Number} numberOfJumps
  884. * @param {Number} amplitude
  885. */
  886. cc.JumpTiles3D = cc.TiledGrid3DAction.extend(/** @lends cc.JumpTiles3D# */{
  887. _jumps:0,
  888. _amplitude:0,
  889. _amplitudeRate:0,
  890. /**
  891. * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br />
  892. * creates the action with the number of jumps, the sin amplitude, the grid size and the duration.
  893. * @param {Number} duration
  894. * @param {cc.Size} gridSize
  895. * @param {Number} numberOfJumps
  896. * @param {Number} amplitude
  897. */
  898. ctor:function (duration, gridSize, numberOfJumps, amplitude) {
  899. cc.GridAction.prototype.ctor.call(this);
  900. amplitude !== undefined && this.initWithDuration(duration, gridSize, numberOfJumps, amplitude);
  901. },
  902. /**
  903. * get amplitude of the sin
  904. * @return {Number}
  905. */
  906. getAmplitude:function () {
  907. return this._amplitude;
  908. },
  909. /**
  910. * set amplitude of the sin
  911. * @param {Number} amplitude
  912. */
  913. setAmplitude:function (amplitude) {
  914. this._amplitude = amplitude;
  915. },
  916. /**
  917. * get amplitude rate
  918. * @return {Number}
  919. */
  920. getAmplitudeRate:function () {
  921. return this._amplitudeRate;
  922. },
  923. /**
  924. * set amplitude rate
  925. * @param amplitudeRate
  926. */
  927. setAmplitudeRate:function (amplitudeRate) {
  928. this._amplitudeRate = amplitudeRate;
  929. },
  930. /**
  931. * initializes the action with the number of jumps, the sin amplitude, the grid size and the duration
  932. * @param {Number} duration
  933. * @param {cc.Size} gridSize
  934. * @param {Number} numberOfJumps
  935. * @param {Number} amplitude
  936. */
  937. initWithDuration:function (duration, gridSize, numberOfJumps, amplitude) {
  938. if (cc.TiledGrid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) {
  939. this._jumps = numberOfJumps;
  940. this._amplitude = amplitude;
  941. this._amplitudeRate = 1.0;
  942. return true;
  943. }
  944. return false;
  945. },
  946. /**
  947. * Called once per frame. Time is the number of seconds of a frame interval.
  948. * @param {Number} dt
  949. */
  950. update:function (dt) {
  951. var sinz = (Math.sin(Math.PI * dt * this._jumps * 2) * this._amplitude * this._amplitudeRate );
  952. var sinz2 = (Math.sin(Math.PI * (dt * this._jumps * 2 + 1)) * this._amplitude * this._amplitudeRate );
  953. var locGridSize = this._gridSize;
  954. var locGrid = this.target.grid;
  955. var coords, locPos = cc.p(0, 0);
  956. for (var i = 0; i < locGridSize.width; i++) {
  957. for (var j = 0; j < locGridSize.height; j++) {
  958. locPos.x = i;
  959. locPos.y = j;
  960. //hack for html5
  961. //var coords = this.originalTile(cc.p(i, j));
  962. coords = locGrid.originalTile(locPos);
  963. if (((i + j) % 2) == 0) {
  964. coords.bl.z += sinz;
  965. coords.br.z += sinz;
  966. coords.tl.z += sinz;
  967. coords.tr.z += sinz;
  968. } else {
  969. coords.bl.z += sinz2;
  970. coords.br.z += sinz2;
  971. coords.tl.z += sinz2;
  972. coords.tr.z += sinz2;
  973. }
  974. //hack for html5
  975. //this.setTile(cc.p(i, j), coords);
  976. locGrid.setTile(locPos, coords);
  977. }
  978. }
  979. }
  980. });
  981. /**
  982. * creates the action with the number of jumps, the sin amplitude, the grid size and the duration. <br />
  983. * Reference the test cases (Effects Test)
  984. * @function
  985. * @param {Number} duration
  986. * @param {cc.Size} gridSize
  987. * @param {Number} numberOfJumps
  988. * @param {Number} amplitude
  989. * @return {cc.JumpTiles3D}
  990. */
  991. cc.jumpTiles3D = function (duration, gridSize, numberOfJumps, amplitude) {
  992. return new cc.JumpTiles3D(duration, gridSize, numberOfJumps, amplitude);
  993. };
  994. /**
  995. * Please use cc.jumpTiles3D instead
  996. * creates the action with the number of jumps, the sin amplitude, the grid size and the duration. <br />
  997. * Reference the test cases (Effects Test)
  998. * @param {Number} duration
  999. * @param {cc.Size} gridSize
  1000. * @param {Number} numberOfJumps
  1001. * @param {Number} amplitude
  1002. * @return {cc.JumpTiles3D}
  1003. * @static
  1004. * @deprecated since v3.0 <br /> Please use cc.jumpTiles3D instead.
  1005. */
  1006. cc.JumpTiles3D.create = cc.jumpTiles3D;
  1007. /**
  1008. * cc.SplitRows action. <br />
  1009. * Reference the test cases (Effects Test)
  1010. * @class
  1011. * @extends cc.TiledGrid3DAction
  1012. * @param {Number} duration
  1013. * @param {Number} rows
  1014. */
  1015. cc.SplitRows = cc.TiledGrid3DAction.extend(/** @lends cc.SplitRows# */{
  1016. _rows:0,
  1017. _winSize:null,
  1018. /**
  1019. * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br />
  1020. * creates the action with the number of rows to split and the duration.
  1021. * @param {Number} duration
  1022. * @param {Number} rows
  1023. */
  1024. ctor:function (duration, rows) {
  1025. cc.GridAction.prototype.ctor.call(this);
  1026. rows !== undefined && this.initWithDuration(duration, rows);
  1027. },
  1028. /**
  1029. * initializes the action with the number of rows to split and the duration
  1030. * @param {Number} duration
  1031. * @param {Number} rows
  1032. * @return {Boolean}
  1033. */
  1034. initWithDuration:function (duration, rows) {
  1035. this._rows = rows;
  1036. return cc.TiledGrid3DAction.prototype.initWithDuration.call(this, duration, cc.size(1, rows));
  1037. },
  1038. /**
  1039. * Called once per frame. Time is the number of seconds of a frame interval.
  1040. * @param {Number} dt
  1041. */
  1042. update:function (dt) {
  1043. var locGridSize = this._gridSize, locWinSizeWidth = this._winSize.width;
  1044. var coords, direction, locPos = cc.p(0, 0);
  1045. for (var j = 0; j < locGridSize.height; ++j) {
  1046. locPos.y = j;
  1047. coords = this.originalTile(locPos);
  1048. direction = 1;
  1049. if ((j % 2 ) == 0)
  1050. direction = -1;
  1051. coords.bl.x += direction * locWinSizeWidth * dt;
  1052. coords.br.x += direction * locWinSizeWidth * dt;
  1053. coords.tl.x += direction * locWinSizeWidth * dt;
  1054. coords.tr.x += direction * locWinSizeWidth * dt;
  1055. this.setTile(locPos, coords);
  1056. }
  1057. },
  1058. /**
  1059. * called before the action start. It will also set the target.
  1060. * @param {cc.Node} target
  1061. */
  1062. startWithTarget:function (target) {
  1063. cc.TiledGrid3DAction.prototype.startWithTarget.call(this, target);
  1064. this._winSize = cc.director.getWinSizeInPixels();
  1065. }
  1066. });
  1067. /**
  1068. * creates the action with the number of rows to split and the duration. <br />
  1069. * Reference the test cases (Effects Test)
  1070. * @function
  1071. * @param {Number} duration
  1072. * @param {Number} rows
  1073. * @return {cc.SplitRows}
  1074. */
  1075. cc.splitRows = function (duration, rows) {
  1076. return new cc.SplitRows(duration, rows);
  1077. };
  1078. /**
  1079. * Please use cc.splitRows instead
  1080. * creates the action with the number of rows to split and the duration. <br />
  1081. * Reference the test cases (Effects Test)
  1082. * @param {Number} duration
  1083. * @param {Number} rows
  1084. * @return {cc.SplitRows}
  1085. * @static
  1086. * @deprecated since v3.0 <br /> Please use cc.splitRows instead.
  1087. */
  1088. cc.SplitRows.create = cc.splitRows;
  1089. /**
  1090. * cc.SplitCols action. <br />
  1091. * Reference the test cases (Effects Test)
  1092. * @class
  1093. * @extends cc.TiledGrid3DAction
  1094. * @param {Number} duration
  1095. * @param {Number} cols
  1096. */
  1097. cc.SplitCols = cc.TiledGrid3DAction.extend(/** @lends cc.SplitCols# */{
  1098. _cols:0,
  1099. _winSize:null,
  1100. /**
  1101. * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br />
  1102. * Creates the action with the number of columns to split and the duration.
  1103. * @param {Number} duration
  1104. * @param {Number} cols
  1105. */
  1106. ctor:function (duration, cols) {
  1107. cc.GridAction.prototype.ctor.call(this);
  1108. cols !== undefined && this.initWithDuration(duration, cols);
  1109. },
  1110. /**
  1111. * initializes the action with the number of columns to split and the duration
  1112. * @param {Number} duration
  1113. * @param {Number} cols
  1114. * @return {Boolean}
  1115. */
  1116. initWithDuration:function (duration, cols) {
  1117. this._cols = cols;
  1118. return cc.TiledGrid3DAction.prototype.initWithDuration.call(this, duration, cc.size(cols, 1));
  1119. },
  1120. /**
  1121. * Called once per frame. Time is the number of seconds of a frame interval.
  1122. * @param {Number} dt
  1123. */
  1124. update:function (dt) {
  1125. var locGridSizeWidth = this._gridSize.width, locWinSizeHeight = this._winSize.height;
  1126. var coords, direction, locPos = cc.p(0, 0);
  1127. for (var i = 0; i < locGridSizeWidth; ++i) {
  1128. locPos.x = i;
  1129. coords = this.originalTile(locPos);
  1130. direction = 1;
  1131. if ((i % 2 ) == 0)
  1132. direction = -1;
  1133. coords.bl.y += direction * locWinSizeHeight * dt;
  1134. coords.br.y += direction * locWinSizeHeight * dt;
  1135. coords.tl.y += direction * locWinSizeHeight * dt;
  1136. coords.tr.y += direction * locWinSizeHeight * dt;
  1137. this.setTile(locPos, coords);
  1138. }
  1139. },
  1140. /**
  1141. * called before the action start. It will also set the target.
  1142. * @param {cc.Node} target
  1143. */
  1144. startWithTarget:function (target) {
  1145. cc.TiledGrid3DAction.prototype.startWithTarget.call(this, target);
  1146. this._winSize = cc.director.getWinSizeInPixels();
  1147. }
  1148. });
  1149. /**
  1150. * creates the action with the number of columns to split and the duration. <br />
  1151. * Reference the test cases (Effects Test)
  1152. * @function
  1153. * @param {Number} duration
  1154. * @param {Number} cols
  1155. * @return {cc.SplitCols}
  1156. */
  1157. cc.splitCols = function (duration, cols) {
  1158. return new cc.SplitCols(duration, cols);
  1159. };
  1160. /**
  1161. * Please use cc.splitCols instead.
  1162. * creates the action with the number of columns to split and the duration. <br />
  1163. * Reference the test cases (Effects Test)
  1164. * @param {Number} duration
  1165. * @param {Number} cols
  1166. * @return {cc.SplitCols}
  1167. * @static
  1168. * @deprecated since v3.0 <br /> Please use cc.splitCols instead.
  1169. */
  1170. cc.SplitCols.create = cc.splitCols;