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