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