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.Point} 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 === this._gridSize.width && locY === this._gridSize.height) return 0.0; 461 if ((locX + locY) === 0.0) 462 return 1.0; 463 return Math.pow((pos.x + pos.y) / (locX + locY), 6); 464 }, 465 466 /** 467 * Turn on Tile 468 * @param {cc.Point} pos 469 */ 470 turnOnTile:function (pos) { 471 this.setTile(pos, this.originalTile(pos)); 472 }, 473 474 /** 475 * Turn Off Tile 476 * @param {cc.Point} pos 477 */ 478 turnOffTile:function (pos) { 479 this.setTile(pos, new cc.Quad3()); 480 }, 481 482 /** 483 * Transform tile 484 * @param {cc.Point} pos 485 * @param {Number} distance 486 */ 487 transformTile:function (pos, distance) { 488 var coords = this.originalTile(pos); 489 var step = this.target.grid.getStep(); 490 491 coords.bl.x += (step.x / 2) * (1.0 - distance); 492 coords.bl.y += (step.y / 2) * (1.0 - distance); 493 494 coords.br.x -= (step.x / 2) * (1.0 - distance); 495 coords.br.y += (step.y / 2) * (1.0 - distance); 496 497 coords.tl.x += (step.x / 2) * (1.0 - distance); 498 coords.tl.y -= (step.y / 2) * (1.0 - distance); 499 500 coords.tr.x -= (step.x / 2) * (1.0 - distance); 501 coords.tr.y -= (step.y / 2) * (1.0 - distance); 502 503 this.setTile(pos, coords); 504 }, 505 506 /** 507 * Called once per frame. Time is the number of seconds of a frame interval. 508 * @param {Number} dt 509 */ 510 update:function (dt) { 511 var locGridSize = this._gridSize; 512 var locPos = cc.p(0, 0), distance; 513 for (var i = 0; i < locGridSize.width; ++i) { 514 for (var j = 0; j < locGridSize.height; ++j) { 515 locPos.x = i; 516 locPos.y = j; 517 distance = this.testFunc(locPos, dt); 518 if (distance === 0) 519 this.turnOffTile(locPos); 520 else if (distance < 1) 521 this.transformTile(locPos, distance); 522 else 523 this.turnOnTile(locPos); 524 } 525 } 526 } 527 }); 528 529 /** 530 * Creates the action with the grid size and the duration. <br /> 531 * Reference the test cases (Effects Test) 532 * @function 533 * @param duration 534 * @param gridSize 535 * @return {cc.FadeOutTRTiles} 536 */ 537 cc.fadeOutTRTiles = function (duration, gridSize) { 538 return new cc.FadeOutTRTiles(duration, gridSize); 539 }; 540 541 /** 542 * Please use cc.fadeOutTRTiles instead. <br /> 543 * Creates the action with the grid size and the duration. <br /> 544 * Reference the test cases (Effects Test) 545 * @param duration 546 * @param gridSize 547 * @return {cc.FadeOutTRTiles} 548 * @static 549 * @deprecated since v3.0 <br /> Please use cc.fadeOutTRTiles instead. 550 */ 551 cc.FadeOutTRTiles.create = cc.fadeOutTRTiles; 552 553 /** 554 * cc.FadeOutBLTiles action. Fades out the tiles in a Bottom-Left direction. <br /> 555 * Reference the test cases (Effects Test) 556 * @class 557 * @extends cc.FadeOutTRTiles 558 */ 559 cc.FadeOutBLTiles = cc.FadeOutTRTiles.extend(/** @lends cc.FadeOutBLTiles# */{ 560 /** 561 * Test function 562 * @param {cc.Point} pos 563 * @param {Number} time 564 */ 565 testFunc:function (pos, time) { 566 var locX = this._gridSize.width * (1.0 - time); 567 var locY = this._gridSize.height * (1.0 - time); 568 if ((locX + locY) === 0) 569 return 0.0; 570 if ((pos.x + pos.y) === 0) 571 return 1.0; 572 573 return Math.pow((locX + locY) / (pos.x + pos.y), 6); 574 } 575 }); 576 577 /** 578 * Creates the action with the grid size and the duration. <br /> 579 * Reference the test cases (Effects Test) 580 * @function 581 * @param duration 582 * @param gridSize 583 * @return {cc.FadeOutBLTiles} 584 */ 585 cc.fadeOutBLTiles = function (duration, gridSize) { 586 return new cc.FadeOutBLTiles(duration, gridSize); 587 }; 588 589 /** 590 * Please use cc.fadeOutBLTiles instead. <br /> 591 * Creates the action with the grid size and the duration. <br /> 592 * Reference the test cases (Effects Test) 593 * @param duration 594 * @param gridSize 595 * @return {cc.FadeOutBLTiles} 596 * @static 597 * @deprecated since v3.0 <br /> Please use cc.fadeOutBLTiles instead. 598 */ 599 cc.FadeOutBLTiles.create = cc.fadeOutBLTiles; 600 601 /** 602 * cc.FadeOutUpTiles action. Fades out the tiles in upwards direction. <br /> 603 * Reference the test cases (Effects Test) 604 * @class 605 * @extends cc.FadeOutTRTiles 606 */ 607 cc.FadeOutUpTiles = cc.FadeOutTRTiles.extend(/** @lends cc.FadeOutUpTiles# */{ 608 /** 609 * Test function 610 * @param {cc.Point} pos 611 * @param {Number} time 612 */ 613 testFunc:function (pos, time) { 614 var locY = this._gridSize.height * time; 615 if( locY === this._gridSize.height) return 0.0; 616 if (locY === 0.0) return 1.0; 617 return Math.pow(pos.y / locY, 6); 618 }, 619 620 transformTile:function (pos, distance) { 621 var coords = this.originalTile(pos); 622 var step = this.target.grid.getStep(); 623 624 coords.bl.y += (step.y / 2) * (1.0 - distance); 625 coords.br.y += (step.y / 2) * (1.0 - distance); 626 coords.tl.y -= (step.y / 2) * (1.0 - distance); 627 coords.tr.y -= (step.y / 2) * (1.0 - distance); 628 629 this.setTile(pos, coords); 630 } 631 }); 632 633 /** 634 * Creates the action with the grid size and the duration. <br /> 635 * Reference the test cases (Effects Test) 636 * @function 637 * @param {Number} duration 638 * @param {cc.Size} gridSize 639 * @return {cc.FadeOutUpTiles} 640 */ 641 cc.fadeOutUpTiles = function (duration, gridSize) { 642 return new cc.FadeOutUpTiles(duration, gridSize); 643 }; 644 645 /** 646 * Please use cc.fadeOutUpTiles instead. <br /> 647 * Creates the action with the grid size and the duration. <br /> 648 * Reference the test cases (Effects Test) 649 * @param {Number} duration 650 * @param {cc.Size} gridSize 651 * @return {cc.FadeOutUpTiles} 652 * @static 653 * @deprecated since v3.0 <br /> Please use cc.fadeOutUpTiles instead. 654 */ 655 cc.FadeOutUpTiles.create = cc.fadeOutUpTiles; 656 657 /** 658 * cc.FadeOutDownTiles action. Fades out the tiles in downwards direction. <br /> 659 * Reference the test cases (Effects Test) 660 * @class 661 * @extends cc.FadeOutUpTiles 662 */ 663 cc.FadeOutDownTiles = cc.FadeOutUpTiles.extend(/** @lends cc.FadeOutDownTiles# */{ 664 /** 665 * Test function 666 * @param {cc.Point} pos 667 * @param {Number} time 668 */ 669 testFunc:function (pos, time) { 670 var locY = this._gridSize.height * (1.0 - time); 671 if( locY === 0.0 ) return 0.0; 672 if (pos.y === 0) return 1.0; 673 return Math.pow(locY / pos.y, 6); 674 } 675 }); 676 677 /** 678 * Creates the action with the grid size and the duration. <br /> 679 * Reference the test cases (Effects Test) 680 * @function 681 * @param {Number} duration 682 * @param {cc.Size} gridSize 683 * @return {cc.FadeOutDownTiles} 684 */ 685 cc.fadeOutDownTiles = function (duration, gridSize) { 686 return new cc.FadeOutDownTiles(duration, gridSize); 687 }; 688 /** 689 * Please use cc.fadeOutDownTiles instead. <br /> 690 * Creates the action with the grid size and the duration. <br /> 691 * Reference the test cases (Effects Test) 692 * @param {Number} duration 693 * @param {cc.Size} gridSize 694 * @return {cc.FadeOutDownTiles} 695 * @static 696 * @deprecated since v3.0 <br /> Please use cc.fadeOutDownTiles instead. 697 */ 698 cc.FadeOutDownTiles.create = cc.fadeOutDownTiles; 699 700 /** 701 * cc.TurnOffTiles action.<br/> 702 * Turn off the files in random order. <br /> 703 * Reference the test cases (Effects Test) 704 * @class 705 * @extends cc.TiledGrid3DAction 706 * @param {Number} duration 707 * @param {cc.Size} gridSize 708 * @param {Number|Null} [seed=0] 709 * @example 710 * // turnOffTiles without seed 711 * var toff = new cc.TurnOffTiles(this._duration, cc.size(x, y)); 712 * 713 * // turnOffTiles with seed 714 * var toff = new cc.TurnOffTiles(this._duration, cc.size(x, y), 0); 715 */ 716 cc.TurnOffTiles = cc.TiledGrid3DAction.extend(/** @lends cc.TurnOffTiles# */{ 717 _seed:null, 718 _tilesCount:0, 719 _tilesOrder:null, 720 721 /** 722 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br /> 723 * Creates the action with a random seed, the grid size and the duration. 724 * @param {Number} duration 725 * @param {cc.Size} gridSize 726 * @param {Number|Null} [seed=0] 727 */ 728 ctor:function (duration, gridSize, seed) { 729 cc.GridAction.prototype.ctor.call(this); 730 this._tilesOrder = []; 731 732 gridSize !== undefined && this.initWithDuration(duration, gridSize, seed); 733 }, 734 735 /** 736 * Initializes the action with a random seed, the grid size and the duration. 737 * @param {Number} duration 738 * @param {cc.Size} gridSize 739 * @param {Number|Null} [seed=0] 740 * @return {Boolean} 741 */ 742 initWithDuration:function (duration, gridSize, seed) { 743 if (cc.TiledGrid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) { 744 this._seed = seed || 0; 745 this._tilesOrder.length = 0; 746 return true; 747 } 748 return false; 749 }, 750 751 /** 752 * Shuffle 753 * @param {Array} array 754 * @param {Number} len 755 */ 756 shuffle:function (array, len) { 757 for (var i = len - 1; i >= 0; i--) { 758 var j = 0 | (cc.rand() % (i + 1)); 759 var v = array[i]; 760 array[i] = array[j]; 761 array[j] = v; 762 } 763 }, 764 765 /** 766 * Turn on tile. 767 * @param {cc.Point} pos 768 */ 769 turnOnTile:function (pos) { 770 this.setTile(pos, this.originalTile(pos)); 771 }, 772 773 /** 774 * Turn off title. 775 * @param {cc.Point} pos 776 */ 777 turnOffTile:function (pos) { 778 this.setTile(pos, new cc.Quad3()); 779 }, 780 781 /** 782 * called before the action start. It will also set the target. 783 * @param {cc.Node} target 784 */ 785 startWithTarget:function (target) { 786 cc.TiledGrid3DAction.prototype.startWithTarget.call(this, target); 787 788 this._tilesCount = this._gridSize.width * this._gridSize.height; 789 var locTilesOrder = this._tilesOrder; 790 locTilesOrder.length = 0; 791 for (var i = 0; i < this._tilesCount; ++i) 792 locTilesOrder[i] = i; 793 this.shuffle(locTilesOrder, this._tilesCount); 794 }, 795 796 /** 797 * Called once per frame. Time is the number of seconds of a frame interval. 798 * @param {Number} dt 799 */ 800 update:function (dt) { 801 var l = 0 | (dt * this._tilesCount), locGridSize = this._gridSize; 802 var t,tilePos = cc.p(0,0), locTilesOrder = this._tilesOrder; 803 for (var i = 0; i < this._tilesCount; i++) { 804 t = locTilesOrder[i]; 805 tilePos.x = 0 | (t / locGridSize.height); 806 tilePos.y = t % (0 | locGridSize.height); 807 if (i < l) 808 this.turnOffTile(tilePos); 809 else 810 this.turnOnTile(tilePos); 811 } 812 } 813 }); 814 815 /** 816 * Creates the action with a random seed, the grid size and the duration. <br /> 817 * Reference the test cases (Effects Test) 818 * @function 819 * @param {Number} duration 820 * @param {cc.Size} gridSize 821 * @param {Number|Null} [seed=0] 822 * @return {cc.TurnOffTiles} 823 * @example 824 * // example 825 * // turnOffTiles without seed 826 * var toff = cc.turnOffTiles(this._duration, cc.size(x, y)); 827 * 828 * // turnOffTiles with seed 829 * var toff = cc.turnOffTiles(this._duration, cc.size(x, y), 0); 830 */ 831 cc.turnOffTiles = function (duration, gridSize, seed) { 832 return new cc.TurnOffTiles(duration, gridSize, seed); 833 }; 834 /** 835 * Please use cc.turnOffTiles instead. <br /> 836 * Creates the action with a random seed, the grid size and the duration. <br /> 837 * Reference the test cases (Effects Test) 838 * @param {Number} duration 839 * @param {cc.Size} gridSize 840 * @param {Number|Null} [seed=0] 841 * @return {cc.TurnOffTiles} 842 * @static 843 * @deprecated since v3.0 <br /> Please use cc.turnOffTiles instead. 844 */ 845 cc.TurnOffTiles.create = cc.turnOffTiles; 846 847 /** 848 * cc.WavesTiles3D action. <br /> 849 * Reference the test cases (Effects Test) 850 * @class 851 * @extends cc.TiledGrid3DAction 852 * @param {Number} duration 853 * @param {cc.Size} gridSize 854 * @param {Number} waves 855 * @param {Number} amplitude 856 */ 857 cc.WavesTiles3D = cc.TiledGrid3DAction.extend(/** @lends cc.WavesTiles3D# */{ 858 _waves:0, 859 _amplitude:0, 860 _amplitudeRate:0, 861 862 /** 863 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br /> 864 * creates the action with a number of waves, the waves amplitude, the grid size and the duration. 865 * @param {Number} duration 866 * @param {cc.Size} gridSize 867 * @param {Number} waves 868 * @param {Number} amplitude 869 */ 870 ctor:function (duration, gridSize, waves, amplitude) { 871 cc.GridAction.prototype.ctor.call(this); 872 amplitude !== undefined && this.initWithDuration(duration, gridSize, waves, amplitude); 873 }, 874 875 /** 876 * get amplitude of waves 877 * @return {Number} 878 */ 879 getAmplitude:function () { 880 return this._amplitude; 881 }, 882 883 /** 884 * set amplitude of waves 885 * @param {Number} amplitude 886 */ 887 setAmplitude:function (amplitude) { 888 this._amplitude = amplitude; 889 }, 890 891 /** 892 * get amplitude rate of waves 893 * @return {Number} 894 */ 895 getAmplitudeRate:function () { 896 return this._amplitudeRate; 897 }, 898 899 /** 900 * set amplitude rate of waves 901 * @param {Number} amplitudeRate 902 */ 903 setAmplitudeRate:function (amplitudeRate) { 904 this._amplitudeRate = amplitudeRate; 905 }, 906 907 /** 908 * initializes the action with a number of waves, the waves amplitude, the grid size and the duration 909 * @param {Number} duration 910 * @param {cc.Size} gridSize 911 * @param {Number} waves 912 * @param {Number} amplitude 913 * @return {Boolean} 914 */ 915 initWithDuration:function (duration, gridSize, waves, amplitude) { 916 if (cc.TiledGrid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) { 917 this._waves = waves; 918 this._amplitude = amplitude; 919 this._amplitudeRate = 1.0; 920 return true; 921 } 922 return false; 923 }, 924 925 /** 926 * Called once per frame. Time is the number of seconds of a frame interval. 927 * @param {Number} dt 928 */ 929 update:function (dt) { 930 var locGridSize = this._gridSize, locWaves = this._waves, locAmplitude = this._amplitude, locAmplitudeRate = this._amplitudeRate; 931 var locPos = cc.p(0, 0), coords; 932 for (var i = 0; i < locGridSize.width; i++) { 933 for (var j = 0; j < locGridSize.height; j++) { 934 locPos.x = i; 935 locPos.y = j; 936 coords = this.originalTile(locPos); 937 coords.bl.z = (Math.sin(dt * Math.PI * locWaves * 2 + 938 (coords.bl.y + coords.bl.x) * 0.01) * locAmplitude * locAmplitudeRate); 939 coords.br.z = coords.bl.z; 940 coords.tl.z = coords.bl.z; 941 coords.tr.z = coords.bl.z; 942 this.setTile(locPos, coords); 943 } 944 } 945 } 946 }); 947 948 /** 949 * creates the action with a number of waves, the waves amplitude, the grid size and the duration. <br /> 950 * Reference the test cases (Effects Test) 951 * @function 952 * @param {Number} duration 953 * @param {cc.Size} gridSize 954 * @param {Number} waves 955 * @param {Number} amplitude 956 * @return {cc.WavesTiles3D} 957 */ 958 cc.wavesTiles3D = function (duration, gridSize, waves, amplitude) { 959 return new cc.WavesTiles3D(duration, gridSize, waves, amplitude); 960 }; 961 /** 962 * Please use cc.wavesTiles3D instead 963 * creates the action with a number of waves, the waves amplitude, the grid size and the duration. <br /> 964 * Reference the test cases (Effects Test) 965 * @param {Number} duration 966 * @param {cc.Size} gridSize 967 * @param {Number} waves 968 * @param {Number} amplitude 969 * @return {cc.WavesTiles3D} 970 * @static 971 * @deprecated since v3.0 <br /> Please use cc.wavesTiles3D instead. 972 */ 973 cc.WavesTiles3D.create = cc.wavesTiles3D; 974 975 /** 976 * cc.JumpTiles3D action. A sin function is executed to move the tiles across the Z axis. <br /> 977 * Reference the test cases (Effects Test) 978 * @class 979 * @extends cc.TiledGrid3DAction 980 * @param {Number} duration 981 * @param {cc.Size} gridSize 982 * @param {Number} numberOfJumps 983 * @param {Number} amplitude 984 */ 985 cc.JumpTiles3D = cc.TiledGrid3DAction.extend(/** @lends cc.JumpTiles3D# */{ 986 _jumps:0, 987 _amplitude:0, 988 _amplitudeRate:0, 989 990 /** 991 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br /> 992 * creates the action with the number of jumps, the sin amplitude, the grid size and the duration. 993 * @param {Number} duration 994 * @param {cc.Size} gridSize 995 * @param {Number} numberOfJumps 996 * @param {Number} amplitude 997 */ 998 ctor:function (duration, gridSize, numberOfJumps, amplitude) { 999 cc.GridAction.prototype.ctor.call(this); 1000 amplitude !== undefined && this.initWithDuration(duration, gridSize, numberOfJumps, amplitude); 1001 }, 1002 1003 /** 1004 * get amplitude of the sin 1005 * @return {Number} 1006 */ 1007 getAmplitude:function () { 1008 return this._amplitude; 1009 }, 1010 1011 /** 1012 * set amplitude of the sin 1013 * @param {Number} amplitude 1014 */ 1015 setAmplitude:function (amplitude) { 1016 this._amplitude = amplitude; 1017 }, 1018 1019 /** 1020 * get amplitude rate 1021 * @return {Number} 1022 */ 1023 getAmplitudeRate:function () { 1024 return this._amplitudeRate; 1025 }, 1026 1027 /** 1028 * set amplitude rate 1029 * @param amplitudeRate 1030 */ 1031 setAmplitudeRate:function (amplitudeRate) { 1032 this._amplitudeRate = amplitudeRate; 1033 }, 1034 1035 /** 1036 * initializes the action with the number of jumps, the sin amplitude, the grid size and the duration 1037 * @param {Number} duration 1038 * @param {cc.Size} gridSize 1039 * @param {Number} numberOfJumps 1040 * @param {Number} amplitude 1041 */ 1042 initWithDuration:function (duration, gridSize, numberOfJumps, amplitude) { 1043 if (cc.TiledGrid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) { 1044 this._jumps = numberOfJumps; 1045 this._amplitude = amplitude; 1046 this._amplitudeRate = 1.0; 1047 return true; 1048 } 1049 return false; 1050 }, 1051 1052 /** 1053 * Called once per frame. Time is the number of seconds of a frame interval. 1054 * @param {Number} dt 1055 */ 1056 update:function (dt) { 1057 var sinz = (Math.sin(Math.PI * dt * this._jumps * 2) * this._amplitude * this._amplitudeRate ); 1058 var sinz2 = (Math.sin(Math.PI * (dt * this._jumps * 2 + 1)) * this._amplitude * this._amplitudeRate ); 1059 1060 var locGridSize = this._gridSize; 1061 var locGrid = this.target.grid; 1062 var coords, locPos = cc.p(0, 0); 1063 for (var i = 0; i < locGridSize.width; i++) { 1064 for (var j = 0; j < locGridSize.height; j++) { 1065 locPos.x = i; 1066 locPos.y = j; 1067 //hack for html5 1068 //var coords = this.originalTile(cc.p(i, j)); 1069 coords = locGrid.originalTile(locPos); 1070 1071 if (((i + j) % 2) === 0) { 1072 coords.bl.z += sinz; 1073 coords.br.z += sinz; 1074 coords.tl.z += sinz; 1075 coords.tr.z += sinz; 1076 } else { 1077 coords.bl.z += sinz2; 1078 coords.br.z += sinz2; 1079 coords.tl.z += sinz2; 1080 coords.tr.z += sinz2; 1081 } 1082 //hack for html5 1083 //this.setTile(cc.p(i, j), coords); 1084 locGrid.setTile(locPos, coords); 1085 } 1086 } 1087 } 1088 }); 1089 1090 /** 1091 * creates the action with the number of jumps, the sin amplitude, the grid size and the duration. <br /> 1092 * Reference the test cases (Effects Test) 1093 * @function 1094 * @param {Number} duration 1095 * @param {cc.Size} gridSize 1096 * @param {Number} numberOfJumps 1097 * @param {Number} amplitude 1098 * @return {cc.JumpTiles3D} 1099 */ 1100 cc.jumpTiles3D = function (duration, gridSize, numberOfJumps, amplitude) { 1101 return new cc.JumpTiles3D(duration, gridSize, numberOfJumps, amplitude); 1102 }; 1103 1104 /** 1105 * Please use cc.jumpTiles3D instead 1106 * creates the action with the number of jumps, the sin amplitude, the grid size and the duration. <br /> 1107 * Reference the test cases (Effects Test) 1108 * @param {Number} duration 1109 * @param {cc.Size} gridSize 1110 * @param {Number} numberOfJumps 1111 * @param {Number} amplitude 1112 * @return {cc.JumpTiles3D} 1113 * @static 1114 * @deprecated since v3.0 <br /> Please use cc.jumpTiles3D instead. 1115 */ 1116 cc.JumpTiles3D.create = cc.jumpTiles3D; 1117 1118 /** 1119 * cc.SplitRows action. <br /> 1120 * Reference the test cases (Effects Test) 1121 * @class 1122 * @extends cc.TiledGrid3DAction 1123 * @param {Number} duration 1124 * @param {Number} rows 1125 */ 1126 cc.SplitRows = cc.TiledGrid3DAction.extend(/** @lends cc.SplitRows# */{ 1127 _rows:0, 1128 _winSize:null, 1129 1130 /** 1131 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br /> 1132 * creates the action with the number of rows to split and the duration. 1133 * @param {Number} duration 1134 * @param {Number} rows 1135 */ 1136 ctor:function (duration, rows) { 1137 cc.GridAction.prototype.ctor.call(this); 1138 rows !== undefined && this.initWithDuration(duration, rows); 1139 }, 1140 1141 /** 1142 * initializes the action with the number of rows to split and the duration 1143 * @param {Number} duration 1144 * @param {Number} rows 1145 * @return {Boolean} 1146 */ 1147 initWithDuration:function (duration, rows) { 1148 this._rows = rows; 1149 return cc.TiledGrid3DAction.prototype.initWithDuration.call(this, duration, cc.size(1, rows)); 1150 }, 1151 1152 /** 1153 * Called once per frame. Time is the number of seconds of a frame interval. 1154 * @param {Number} dt 1155 */ 1156 update:function (dt) { 1157 var locGridSize = this._gridSize, locWinSizeWidth = this._winSize.width; 1158 var coords, direction, locPos = cc.p(0, 0); 1159 for (var j = 0; j < locGridSize.height; ++j) { 1160 locPos.y = j; 1161 coords = this.originalTile(locPos); 1162 direction = 1; 1163 1164 if ((j % 2 ) === 0) 1165 direction = -1; 1166 1167 coords.bl.x += direction * locWinSizeWidth * dt; 1168 coords.br.x += direction * locWinSizeWidth * dt; 1169 coords.tl.x += direction * locWinSizeWidth * dt; 1170 coords.tr.x += direction * locWinSizeWidth * dt; 1171 1172 this.setTile(locPos, coords); 1173 } 1174 }, 1175 1176 /** 1177 * called before the action start. It will also set the target. 1178 * @param {cc.Node} target 1179 */ 1180 startWithTarget:function (target) { 1181 cc.TiledGrid3DAction.prototype.startWithTarget.call(this, target); 1182 this._winSize = cc.director.getWinSizeInPixels(); 1183 } 1184 }); 1185 1186 /** 1187 * creates the action with the number of rows to split and the duration. <br /> 1188 * Reference the test cases (Effects Test) 1189 * @function 1190 * @param {Number} duration 1191 * @param {Number} rows 1192 * @return {cc.SplitRows} 1193 */ 1194 cc.splitRows = function (duration, rows) { 1195 return new cc.SplitRows(duration, rows); 1196 }; 1197 1198 /** 1199 * Please use cc.splitRows instead 1200 * creates the action with the number of rows to split and the duration. <br /> 1201 * Reference the test cases (Effects Test) 1202 * @param {Number} duration 1203 * @param {Number} rows 1204 * @return {cc.SplitRows} 1205 * @static 1206 * @deprecated since v3.0 <br /> Please use cc.splitRows instead. 1207 */ 1208 cc.SplitRows.create = cc.splitRows; 1209 1210 /** 1211 * cc.SplitCols action. <br /> 1212 * Reference the test cases (Effects Test) 1213 * @class 1214 * @extends cc.TiledGrid3DAction 1215 * @param {Number} duration 1216 * @param {Number} cols 1217 */ 1218 cc.SplitCols = cc.TiledGrid3DAction.extend(/** @lends cc.SplitCols# */{ 1219 _cols:0, 1220 _winSize:null, 1221 1222 /** 1223 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br /> 1224 * Creates the action with the number of columns to split and the duration. 1225 * @param {Number} duration 1226 * @param {Number} cols 1227 */ 1228 ctor:function (duration, cols) { 1229 cc.GridAction.prototype.ctor.call(this); 1230 cols !== undefined && this.initWithDuration(duration, cols); 1231 }, 1232 /** 1233 * initializes the action with the number of columns to split and the duration 1234 * @param {Number} duration 1235 * @param {Number} cols 1236 * @return {Boolean} 1237 */ 1238 initWithDuration:function (duration, cols) { 1239 this._cols = cols; 1240 return cc.TiledGrid3DAction.prototype.initWithDuration.call(this, duration, cc.size(cols, 1)); 1241 }, 1242 1243 /** 1244 * Called once per frame. Time is the number of seconds of a frame interval. 1245 * @param {Number} dt 1246 */ 1247 update:function (dt) { 1248 var locGridSizeWidth = this._gridSize.width, locWinSizeHeight = this._winSize.height; 1249 var coords, direction, locPos = cc.p(0, 0); 1250 for (var i = 0; i < locGridSizeWidth; ++i) { 1251 locPos.x = i; 1252 coords = this.originalTile(locPos); 1253 direction = 1; 1254 1255 if ((i % 2 ) === 0) 1256 direction = -1; 1257 1258 coords.bl.y += direction * locWinSizeHeight * dt; 1259 coords.br.y += direction * locWinSizeHeight * dt; 1260 coords.tl.y += direction * locWinSizeHeight * dt; 1261 coords.tr.y += direction * locWinSizeHeight * dt; 1262 1263 this.setTile(locPos, coords); 1264 } 1265 cc.renderer.childrenOrderDirty = true; 1266 }, 1267 1268 /** 1269 * called before the action start. It will also set the target. 1270 * @param {cc.Node} target 1271 */ 1272 startWithTarget:function (target) { 1273 cc.TiledGrid3DAction.prototype.startWithTarget.call(this, target); 1274 this._winSize = cc.director.getWinSizeInPixels(); 1275 } 1276 }); 1277 1278 /** 1279 * creates the action with the number of columns to split and the duration. <br /> 1280 * Reference the test cases (Effects Test) 1281 * @function 1282 * @param {Number} duration 1283 * @param {Number} cols 1284 * @return {cc.SplitCols} 1285 */ 1286 cc.splitCols = function (duration, cols) { 1287 return new cc.SplitCols(duration, cols); 1288 }; 1289 1290 /** 1291 * Please use cc.splitCols instead. 1292 * creates the action with the number of columns to split and the duration. <br /> 1293 * Reference the test cases (Effects Test) 1294 * @param {Number} duration 1295 * @param {Number} cols 1296 * @return {cc.SplitCols} 1297 * @static 1298 * @deprecated since v3.0 <br /> Please use cc.splitCols instead. 1299 */ 1300 cc.SplitCols.create = cc.splitCols;