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