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