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.Waves3D action 29 * @class 30 * @extends cc.Grid3DAction 31 */ 32 cc.Waves3D = cc.Grid3DAction.extend(/** @lends cc.Waves3D# */{ 33 _waves: 0, 34 _amplitude: 0, 35 _amplitudeRate: 0, 36 37 /** 38 * Create a wave 3d action with duration, grid size, waves and amplitude 39 * @param {Number} duration 40 * @param {cc.Size} gridSize 41 * @param {Number} waves 42 * @param {Number} amplitude 43 */ 44 ctor:function (duration, gridSize, waves, amplitude) { 45 cc.GridAction.prototype.ctor.call(this); 46 amplitude !== undefined && this.initWithDuration(duration, gridSize, waves, amplitude); 47 }, 48 49 /** 50 * get Amplitude 51 * @return {Number} 52 */ 53 getAmplitude:function () { 54 return this._amplitude; 55 }, 56 57 /** 58 * set Amplitude 59 * @param {Number} amplitude 60 */ 61 setAmplitude:function (amplitude) { 62 this._amplitude = amplitude; 63 }, 64 65 /** 66 * get Amplitude Rate 67 * @return {Number} 68 */ 69 getAmplitudeRate:function () { 70 return this._amplitudeRate; 71 }, 72 73 /** 74 * set Amplitude Rate 75 * @param {Number} amplitudeRate 76 */ 77 setAmplitudeRate:function (amplitudeRate) { 78 this._amplitudeRate = amplitudeRate; 79 }, 80 81 /** 82 * initializes an action with duration, grid size, waves and amplitude 83 * @param {Number} duration 84 * @param {cc.Size} gridSize 85 * @param {Number} waves 86 * @param {Number} amplitude 87 * @return {Boolean} 88 */ 89 initWithDuration:function (duration, gridSize, waves, amplitude) { 90 if (cc.Grid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) { 91 this._waves = waves; 92 this._amplitude = amplitude; 93 this._amplitudeRate = 1.0; 94 return true; 95 } 96 return false; 97 }, 98 99 update:function (time) { 100 var locGridSize = this._gridSize; 101 var locAmplitude = this._amplitude, locPos = cc.p(0, 0); 102 var locAmplitudeRate = this._amplitudeRate, locWaves = this._waves; 103 for (var i = 0; i < locGridSize.width + 1; ++i) { 104 for (var j = 0; j < locGridSize.height + 1; ++j) { 105 locPos.x = i; 106 locPos.y = j; 107 var v = this.originalVertex(locPos); 108 v.z += (Math.sin(Math.PI * time * locWaves * 2 + (v.y + v.x) * 0.01) * locAmplitude * locAmplitudeRate); 109 //cc.log("v.z offset is" + (Math.sin(Math.PI * time * this._waves * 2 + (v.y + v.x) * 0.01) * this._amplitude * this._amplitudeRate)); 110 this.setVertex(locPos, v); 111 } 112 } 113 } 114 }); 115 116 /** 117 * Create a wave 3d action with duration, grid size, waves and amplitude 118 * @function 119 * @param {Number} duration 120 * @param {cc.Size} gridSize 121 * @param {Number} waves 122 * @param {Number} amplitude 123 */ 124 cc.waves3D = function (duration, gridSize, waves, amplitude) { 125 return new cc.Waves3D(duration, gridSize, waves, amplitude); 126 }; 127 /** 128 * Please use cc.waves3D instead 129 * Create a wave 3d action with duration, grid size, waves and amplitude 130 * @param {Number} duration 131 * @param {cc.Size} gridSize 132 * @param {Number} waves 133 * @param {Number} amplitude 134 * @static 135 * @deprecated 136 */ 137 cc.Waves3D.create = cc.waves3D; 138 139 /** 140 * cc.FlipX3D action 141 * @class 142 * @extends cc.Grid3DAction 143 */ 144 cc.FlipX3D = cc.Grid3DAction.extend(/** @lends cc.FlipX3D# */{ 145 146 /** 147 * Create a Flip X 3D action with duration 148 * Constructor of cc.FlipX3D 149 * @param {Number} duration 150 */ 151 ctor: function(duration) { 152 if (duration !== undefined) 153 cc.GridAction.prototype.ctor.call(this, duration, cc.size(1, 1)); 154 else cc.GridAction.prototype.ctor.call(this); 155 }, 156 157 /** 158 * initializes the action with duration 159 * @param {Number} duration 160 * @return {Boolean} 161 */ 162 initWithDuration:function (duration) { 163 return cc.Grid3DAction.prototype.initWithDuration.call(this, duration, cc.size(1, 1)); 164 }, 165 166 /** 167 * initializes the action with gridSize and duration 168 * @param {cc.Size} gridSize 169 * @param {Number} duration 170 * @return {Boolean} 171 */ 172 initWithSize:function (gridSize, duration) { 173 if (gridSize.width != 1 || gridSize.height != 1) { 174 // Grid size must be (1,1) 175 cc.log("Grid size must be (1,1)"); 176 return false; 177 } 178 return cc.Grid3DAction.prototype.initWithDuration.call(this, duration, gridSize); 179 }, 180 181 update:function (time) { 182 var angle = Math.PI * time; // 180 degrees 183 var mz = Math.sin(angle); 184 angle = angle / 2.0; // x calculates degrees from 0 to 90 185 var mx = Math.cos(angle); 186 187 var diff = new cc.Vertex3F(); 188 var tempVer = cc.p(0, 0); 189 tempVer.x = tempVer.y = 1; 190 var v0 = this.originalVertex(tempVer); 191 tempVer.x = tempVer.y = 0; 192 var v1 = this.originalVertex(tempVer); 193 194 var x0 = v0.x; 195 var x1 = v1.x; 196 var x; 197 var a, b, c, d; 198 199 if (x0 > x1) { 200 // Normal Grid 201 a = cc.p(0, 0); 202 b = cc.p(0, 1); 203 c = cc.p(1, 0); 204 d = cc.p(1, 1); 205 x = x0; 206 } else { 207 // Reversed Grid 208 c = cc.p(0, 0); 209 d = cc.p(0, 1); 210 a = cc.p(1, 0); 211 b = cc.p(1, 1); 212 x = x1; 213 } 214 215 diff.x = ( x - x * mx ); 216 diff.z = Math.abs(parseFloat((x * mz) / 4.0)); 217 218 // bottom-left 219 var v = this.originalVertex(a); 220 v.x = diff.x; 221 v.z += diff.z; 222 this.setVertex(a, v); 223 224 // upper-left 225 v = this.originalVertex(b); 226 v.x = diff.x; 227 v.z += diff.z; 228 this.setVertex(b, v); 229 230 // bottom-right 231 v = this.originalVertex(c); 232 v.x -= diff.x; 233 v.z -= diff.z; 234 this.setVertex(c, v); 235 236 // upper-right 237 v = this.originalVertex(d); 238 v.x -= diff.x; 239 v.z -= diff.z; 240 this.setVertex(d, v); 241 } 242 }); 243 244 /** 245 * Create a Flip X 3D action with duration 246 * @function 247 * @param {Number} duration 248 * @return {cc.FlipX3D} 249 */ 250 cc.flipX3D = function (duration) { 251 return new cc.FlipX3D(duration); 252 }; 253 /** 254 * Please use cc.flipX3D instead 255 * Create a Flip X 3D action with duration 256 * @param {Number} duration 257 * @return {cc.FlipX3D} 258 * @static 259 * @deprecated 260 */ 261 cc.FlipX3D.create = cc.flipX3D; 262 263 /** 264 * cc.FlipY3D action 265 * @class 266 * @extends cc.FlipX3D 267 */ 268 cc.FlipY3D = cc.FlipX3D.extend(/** @lends cc.FlipY3D# */{ 269 270 /** 271 * Create a flip Y 3d action with duration 272 * Constructor of cc.FlipY3D 273 * @param {Number} duration 274 */ 275 ctor: function(duration) { 276 if (duration !== undefined) 277 cc.GridAction.prototype.ctor.call(this, duration, cc.size(1, 1)); 278 else cc.GridAction.prototype.ctor.call(this); 279 }, 280 281 update:function (time) { 282 var angle = Math.PI * time; // 180 degrees 283 var mz = Math.sin(angle); 284 angle = angle / 2.0; // x calculates degrees from 0 to 90 285 var my = Math.cos(angle); 286 287 var diff = new cc.Vertex3F(); 288 289 var tempP = cc.p(0, 0); 290 tempP.x = tempP.y = 1; 291 var v0 = this.originalVertex(tempP); 292 tempP.x = tempP.y = 0; 293 var v1 = this.originalVertex(tempP); 294 295 var y0 = v0.y; 296 var y1 = v1.y; 297 var y; 298 var a, b, c, d; 299 300 if (y0 > y1) { 301 // Normal Grid 302 a = cc.p(0, 0); 303 b = cc.p(0, 1); 304 c = cc.p(1, 0); 305 d = cc.p(1, 1); 306 y = y0; 307 } else { 308 // Reversed Grid 309 b = cc.p(0, 0); 310 a = cc.p(0, 1); 311 d = cc.p(1, 0); 312 c = cc.p(1, 1); 313 y = y1; 314 } 315 316 diff.y = y - y * my; 317 diff.z = Math.abs(parseFloat(y * mz) / 4.0); 318 319 // bottom-left 320 var v = this.originalVertex(a); 321 v.y = diff.y; 322 v.z += diff.z; 323 this.setVertex(a, v); 324 325 // upper-left 326 v = this.originalVertex(b); 327 v.y -= diff.y; 328 v.z -= diff.z; 329 this.setVertex(b, v); 330 331 // bottom-right 332 v = this.originalVertex(c); 333 v.y = diff.y; 334 v.z += diff.z; 335 this.setVertex(c, v); 336 337 // upper-right 338 v = this.originalVertex(d); 339 v.y -= diff.y; 340 v.z -= diff.z; 341 this.setVertex(d, v); 342 } 343 }); 344 345 /** 346 * Create a flip Y 3d action with duration 347 * @function 348 * @param {Number} duration 349 * @return {cc.FlipY3D} 350 */ 351 cc.flipY3D = function (duration) { 352 return new cc.FlipY3D(duration); 353 }; 354 /** 355 * Please use cc.flipY3D instead 356 * Create a flip Y 3d action with duration 357 * @param {Number} duration 358 * @return {cc.FlipY3D} 359 * @static 360 * @deprecated 361 */ 362 cc.FlipY3D.create = cc.flipY3D; 363 364 /** 365 * cc.Lens3D action 366 * @class 367 * @extends cc.FlipX3D 368 */ 369 cc.Lens3D = cc.Grid3DAction.extend(/** @lends cc.Lens3D# */{ 370 /* lens center position */ 371 _position:null, 372 _radius:0, 373 /** lens effect. Defaults to 0.7 - 0 means no effect, 1 is very strong effect */ 374 _lensEffect:0, 375 /** lens is concave. (true = concave, false = convex) default is convex i.e. false */ 376 _concave:false, 377 _dirty:false, 378 379 /** 380 * creates a lens 3d action with center position, radius 381 * Constructor of cc.Lens3D 382 * @param {Number} duration 383 * @param {cc.Size} gridSize 384 * @param {cc.Point} position 385 * @param {Number} radius 386 */ 387 ctor:function (duration, gridSize, position, radius) { 388 cc.GridAction.prototype.ctor.call(this); 389 390 this._position = cc.p(0, 0); 391 radius !== undefined && this.initWithDuration(duration, gridSize, position, radius); 392 }, 393 394 /** 395 * Get lens center position 396 * @return {Number} 397 */ 398 getLensEffect:function () { 399 return this._lensEffect; 400 }, 401 402 /** 403 * Set lens center position 404 * @param {Number} lensEffect 405 */ 406 setLensEffect:function (lensEffect) { 407 this._lensEffect = lensEffect; 408 }, 409 410 /** 411 * Set whether lens is concave 412 * @param {Boolean} concave 413 */ 414 setConcave:function (concave) { 415 this._concave = concave; 416 }, 417 418 /** 419 * get Position 420 * @return {cc.Point} 421 */ 422 getPosition:function () { 423 return this._position; 424 }, 425 426 /** 427 * set Position 428 * @param {cc.Point} position 429 */ 430 setPosition:function (position) { 431 if (!cc.pointEqualToPoint(position, this._position)) { 432 this._position.x = position.x; 433 this._position.y = position.y; 434 this._dirty = true; 435 } 436 }, 437 438 /** 439 * initializes the action with center position, radius, a grid size and duration 440 * @param {Number} duration 441 * @param {cc.Size} gridSize 442 * @param {cc.Point} position 443 * @param {Number} radius 444 * @return {Boolean} 445 */ 446 initWithDuration:function (duration, gridSize, position, radius) { 447 if (cc.Grid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) { 448 this.setPosition(position); 449 this._radius = radius; 450 this._lensEffect = 0.7; 451 this._dirty = true; 452 return true; 453 } 454 return false; 455 }, 456 457 update:function (time) { 458 if (this._dirty) { 459 var locGridSizeWidth = this._gridSize.width, locGridSizeHeight = this._gridSize.height; 460 var locRadius = this._radius, locLensEffect = this._lensEffect; 461 var locPos = cc.p(0, 0); 462 var vect = cc.p(0, 0); 463 var v, r, l, new_r, pre_log; 464 for (var i = 0; i < locGridSizeWidth + 1; ++i) { 465 for (var j = 0; j < locGridSizeHeight + 1; ++j) { 466 locPos.x = i; 467 locPos.y = j; 468 v = this.originalVertex(locPos); 469 vect.x = this._position.x - v.x; 470 vect.y = this._position.y - v.y; 471 r = cc.pLength(vect); 472 473 if (r < locRadius) { 474 r = locRadius - r; 475 pre_log = r / locRadius; 476 if (pre_log == 0) 477 pre_log = 0.001; 478 479 l = Math.log(pre_log) * locLensEffect; 480 new_r = Math.exp(l) * locRadius; 481 482 r = cc.pLength(vect); 483 if (r > 0) { 484 vect.x = vect.x / r; 485 vect.y = vect.y / r; 486 487 vect.x = vect.x * new_r; 488 vect.y = vect.y * new_r; 489 v.z += cc.pLength(vect) * locLensEffect; 490 } 491 } 492 this.setVertex(locPos, v); 493 } 494 } 495 this._dirty = false; 496 } 497 } 498 }); 499 500 /** 501 * creates a lens 3d action with center position, radius 502 * @function 503 * @param {Number} duration 504 * @param {cc.Size} gridSize 505 * @param {cc.Point} position 506 * @param {Number} radius 507 * @return {cc.Lens3D} 508 */ 509 cc.lens3D = function (duration, gridSize, position, radius) { 510 return new cc.Lens3D(duration, gridSize, position, radius); 511 }; 512 /** 513 * Please use cc.lens3D instead 514 * creates a lens 3d action with center position, radius 515 * @param {Number} duration 516 * @param {cc.Size} gridSize 517 * @param {cc.Point} position 518 * @param {Number} radius 519 * @return {cc.Lens3D} 520 * @static 521 * @deprecated 522 */ 523 cc.Lens3D.create = cc.lens3D; 524 525 /** 526 * cc.Ripple3D action 527 * @class 528 * @extends cc.Grid3DAction 529 */ 530 cc.Ripple3D = cc.Grid3DAction.extend(/** @lends cc.Ripple3D# */{ 531 /* center position */ 532 _position: null, 533 _radius: 0, 534 _waves: 0, 535 _amplitude: 0, 536 _amplitudeRate: 0, 537 538 /** 539 * creates a ripple 3d action with radius, number of waves, amplitude 540 * Constructor of cc.Ripple3D 541 * @param {Number} duration 542 * @param {cc.Size} gridSize 543 * @param {cc.Point} position 544 * @param {Number} radius 545 * @param {Number} waves 546 * @param {Number} amplitude 547 */ 548 ctor:function (duration, gridSize, position, radius, waves, amplitude) { 549 cc.GridAction.prototype.ctor.call(this); 550 551 this._position = cc.p(0, 0); 552 amplitude !== undefined && this.initWithDuration(duration, gridSize, position, radius, waves, amplitude); 553 }, 554 555 /** 556 * get center position 557 * @return {cc.Point} 558 */ 559 getPosition:function () { 560 return this._position; 561 }, 562 563 /** 564 * set center position 565 * @param {cc.Point} position 566 */ 567 setPosition:function (position) { 568 this._position.x = position.x; 569 this._position.y = position.y; 570 }, 571 572 /** 573 * get Amplitude 574 * @return {Number} 575 */ 576 getAmplitude:function () { 577 return this._amplitude; 578 }, 579 580 /** 581 * set Amplitude 582 * @param {Number} amplitude 583 */ 584 setAmplitude:function (amplitude) { 585 this._amplitude = amplitude; 586 }, 587 588 /** 589 * get Amplitude rate 590 * @return {*} 591 */ 592 getAmplitudeRate:function () { 593 return this._amplitudeRate; 594 }, 595 596 /** 597 * get amplitude rate 598 * @param {Number} amplitudeRate 599 */ 600 setAmplitudeRate:function (amplitudeRate) { 601 this._amplitudeRate = amplitudeRate; 602 }, 603 604 /** 605 * initializes the action with radius, number of waves, amplitude, a grid size and duration 606 * @param {Number} duration 607 * @param {cc.Size} gridSize 608 * @param {cc.Point} position 609 * @param {Number} radius 610 * @param {Number} waves 611 * @param {Number} amplitude 612 * @return {Boolean} 613 */ 614 initWithDuration:function (duration, gridSize, position, radius, waves, amplitude) { 615 if (cc.Grid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) { 616 this.setPosition(position); 617 this._radius = radius; 618 this._waves = waves; 619 this._amplitude = amplitude; 620 this._amplitudeRate = 1.0; 621 return true; 622 } 623 return false; 624 }, 625 626 update:function (time) { 627 var locGridSizeWidth = this._gridSize.width, locGridSizeHeight = this._gridSize.height; 628 var locPos = cc.p(0, 0), locRadius = this._radius; 629 var locWaves = this._waves, locAmplitude = this._amplitude, locAmplitudeRate = this._amplitudeRate; 630 var v, r, tempPos = cc.p(0, 0); 631 for (var i = 0; i < (locGridSizeWidth + 1); ++i) { 632 for (var j = 0; j < (locGridSizeHeight + 1); ++j) { 633 locPos.x = i; 634 locPos.y = j; 635 v = this.originalVertex(locPos); 636 637 tempPos.x = this._position.x - v.x; 638 tempPos.y = this._position.y - v.y; 639 r = cc.pLength(tempPos); 640 641 if (r < locRadius) { 642 r = locRadius - r; 643 var rate = Math.pow(r / locRadius, 2); 644 v.z += (Math.sin(time * Math.PI * locWaves * 2 + r * 0.1) * locAmplitude * locAmplitudeRate * rate); 645 } 646 this.setVertex(locPos, v); 647 } 648 } 649 } 650 }); 651 /** 652 * creates a ripple 3d action with radius, number of waves, amplitude 653 * @function 654 * @param {Number} duration 655 * @param {cc.Size} gridSize 656 * @param {cc.Point} position 657 * @param {Number} radius 658 * @param {Number} waves 659 * @param {Number} amplitude 660 * @return {cc.Ripple3D} 661 */ 662 cc.ripple3D = function (duration, gridSize, position, radius, waves, amplitude) { 663 return new cc.Ripple3D(duration, gridSize, position, radius, waves, amplitude); 664 }; 665 /** 666 * Please use cc.ripple3D instead 667 * creates a ripple 3d action with radius, number of waves, amplitude 668 * @param {Number} duration 669 * @param {cc.Size} gridSize 670 * @param {cc.Point} position 671 * @param {Number} radius 672 * @param {Number} waves 673 * @param {Number} amplitude 674 * @return {cc.Ripple3D} 675 * @static 676 * @deprecated 677 */ 678 cc.Ripple3D.create = cc.ripple3D; 679 680 /** 681 * cc.Shaky3D action 682 * @class 683 * @extends cc.Grid3DAction 684 */ 685 cc.Shaky3D = cc.Grid3DAction.extend(/** @lends cc.Shaky3D# */{ 686 _randRange: 0, 687 _shakeZ: false, 688 689 /** 690 * Create a shaky3d action with a range, shake Z vertices 691 * Constructor of cc.Shaky3D 692 * @param {Number} duration 693 * @param {cc.Size} gridSize 694 * @param {Number} range 695 * @param {Boolean} shakeZ 696 */ 697 ctor:function (duration, gridSize, range, shakeZ) { 698 cc.GridAction.prototype.ctor.call(this); 699 shakeZ !== undefined && this.initWithDuration(duration, gridSize, range, shakeZ); 700 }, 701 702 /** 703 * initializes the action with a range, shake Z vertices, a grid and duration 704 * @param {Number} duration 705 * @param {cc.Size} gridSize 706 * @param {Number} range 707 * @param {Boolean} shakeZ 708 * @return {Boolean} 709 */ 710 initWithDuration:function (duration, gridSize, range, shakeZ) { 711 if (cc.Grid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) { 712 this._randRange = range; 713 this._shakeZ = shakeZ; 714 return true; 715 } 716 return false; 717 }, 718 719 update:function (time) { 720 var locGridSizeWidth = this._gridSize.width, locGridSizeHeight = this._gridSize.height; 721 var locRandRange = this._randRange, locShakeZ = this._shakeZ, locP = cc.p(0, 0); 722 var v; 723 for (var i = 0; i < (locGridSizeWidth + 1); ++i) { 724 for (var j = 0; j < (locGridSizeHeight + 1); ++j) { 725 locP.x = i; 726 locP.y = j; 727 v = this.originalVertex(locP); 728 v.x += (cc.rand() % (locRandRange * 2)) - locRandRange; 729 v.y += (cc.rand() % (locRandRange * 2)) - locRandRange; 730 if (locShakeZ) 731 v.z += (cc.rand() % (locRandRange * 2)) - locRandRange; 732 this.setVertex(locP, v); 733 } 734 } 735 } 736 }); 737 738 /** 739 * creates the action with a range, shake Z vertices, a grid and duration 740 * @function 741 * @param {Number} duration 742 * @param {cc.Size} gridSize 743 * @param {Number} range 744 * @param {Boolean} shakeZ 745 * @return {cc.Shaky3D} 746 */ 747 cc.shaky3D = function (duration, gridSize, range, shakeZ) { 748 return new cc.Shaky3D(duration, gridSize, range, shakeZ); 749 }; 750 /** 751 * Please use cc.shaky3D instead 752 * creates the action with a range, shake Z vertices, a grid and duration 753 * @param {Number} duration 754 * @param {cc.Size} gridSize 755 * @param {Number} range 756 * @param {Boolean} shakeZ 757 * @return {cc.Shaky3D} 758 * @static 759 * @deprecated 760 */ 761 cc.Shaky3D.create = cc.shaky3D; 762 763 /** 764 * cc.Liquid action 765 * @class 766 * @extends cc.Grid3DAction 767 */ 768 cc.Liquid = cc.Grid3DAction.extend(/** @lends cc.Liquid# */{ 769 _waves: 0, 770 _amplitude: 0, 771 _amplitudeRate: 0, 772 773 /** 774 * Create a liquid action with amplitude, a grid and duration 775 * Constructor of cc.Liquid 776 * @param {Number} duration 777 * @param {cc.Size} gridSize 778 * @param {Number} waves 779 * @param {Number} amplitude 780 */ 781 ctor: function (duration, gridSize, waves, amplitude) { 782 cc.GridAction.prototype.ctor.call(this); 783 amplitude !== undefined && this.initWithDuration(duration, gridSize, waves, amplitude); 784 }, 785 786 /** 787 * get amplitude 788 * @return {Number} 789 */ 790 getAmplitude:function () { 791 return this._amplitude; 792 }, 793 794 /** 795 * set amplitude 796 * @param {Number} amplitude 797 */ 798 setAmplitude:function (amplitude) { 799 this._amplitude = amplitude; 800 }, 801 802 /** 803 * get amplitude rate 804 * @return {Number} 805 */ 806 getAmplitudeRate:function () { 807 return this._amplitudeRate; 808 }, 809 810 /** 811 * set amplitude rate 812 * @param {Number} amplitudeRate 813 */ 814 setAmplitudeRate:function (amplitudeRate) { 815 this._amplitudeRate = amplitudeRate; 816 }, 817 818 /** 819 * initializes the action with amplitude, a grid and duration 820 * @param {Number} duration 821 * @param {cc.Size} gridSize 822 * @param {Number} waves 823 * @param {Number} amplitude 824 * @return {Boolean} 825 */ 826 initWithDuration:function (duration, gridSize, waves, amplitude) { 827 if (cc.Grid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) { 828 this._waves = waves; 829 this._amplitude = amplitude; 830 this._amplitudeRate = 1.0; 831 return true; 832 } 833 return false; 834 }, 835 836 update:function (time) { 837 var locSizeWidth = this._gridSize.width, locSizeHeight = this._gridSize.height, locPos = cc.p(0, 0); 838 var locWaves = this._waves, locAmplitude = this._amplitude, locAmplitudeRate = this._amplitudeRate; 839 var v; 840 for (var i = 1; i < locSizeWidth; ++i) { 841 for (var j = 1; j < locSizeHeight; ++j) { 842 locPos.x = i; 843 locPos.y = j; 844 v = this.originalVertex(locPos); 845 v.x = (v.x + (Math.sin(time * Math.PI * locWaves * 2 + v.x * .01) * locAmplitude * locAmplitudeRate)); 846 v.y = (v.y + (Math.sin(time * Math.PI * locWaves * 2 + v.y * .01) * locAmplitude * locAmplitudeRate)); 847 this.setVertex(locPos, v); 848 } 849 } 850 } 851 }); 852 853 /** 854 * creates the action with amplitude, a grid and duration 855 * @function 856 * @param {Number} duration 857 * @param {cc.Size} gridSize 858 * @param {Number} waves 859 * @param {Number} amplitude 860 * @return {cc.Liquid} 861 */ 862 cc.liquid = function (duration, gridSize, waves, amplitude) { 863 return new cc.Liquid(duration, gridSize, waves, amplitude); 864 }; 865 /** 866 * Please use cc.liquid instead 867 * creates the action with amplitude, a grid and duration 868 * @param {Number} duration 869 * @param {cc.Size} gridSize 870 * @param {Number} waves 871 * @param {Number} amplitude 872 * @return {cc.Liquid} 873 * @static 874 * @deprecated 875 */ 876 cc.Liquid.create = cc.liquid; 877 878 /** 879 * cc.Waves action 880 * @class 881 * @extends cc.Grid3DAction 882 */ 883 cc.Waves = cc.Grid3DAction.extend(/** @lends cc.Waves# */{ 884 _waves: 0, 885 _amplitude: 0, 886 _amplitudeRate: 0, 887 _vertical: false, 888 _horizontal: false, 889 890 /** 891 * Create a wave action with amplitude, horizontal sin, vertical sin, a grid and duration 892 * Constructor of cc.Waves 893 * @param {Number} duration 894 * @param {cc.Size} gridSize 895 * @param {Number} waves 896 * @param {Number} amplitude 897 * @param {Boolean} horizontal 898 * @param {Boolean} vertical 899 */ 900 ctor: function (duration, gridSize, waves, amplitude, horizontal, vertical) { 901 cc.GridAction.prototype.ctor.call(this); 902 vertical !== undefined && this.initWithDuration(duration, gridSize, waves, amplitude, horizontal, vertical); 903 }, 904 905 /** 906 * get amplitude 907 * @return {Number} 908 */ 909 getAmplitude:function () { 910 return this._amplitude; 911 }, 912 913 /** 914 * set amplitude 915 * @param {Number} amplitude 916 */ 917 setAmplitude:function (amplitude) { 918 this._amplitude = amplitude; 919 }, 920 921 /** 922 * get amplitude rate 923 * @return {Number} 924 */ 925 getAmplitudeRate:function () { 926 return this._amplitudeRate; 927 }, 928 929 /** 930 * set amplitude rate 931 * @param {Number} amplitudeRate 932 */ 933 setAmplitudeRate:function (amplitudeRate) { 934 this._amplitudeRate = amplitudeRate; 935 }, 936 937 /** 938 * initializes the action with amplitude, horizontal sin, vertical sin, a grid and duration 939 * @param {Number} duration 940 * @param {cc.Size} gridSize 941 * @param {Number} waves 942 * @param {Number} amplitude 943 * @param {Boolean} horizontal 944 * @param {Boolean} vertical 945 * @return {Boolean} 946 */ 947 initWithDuration:function (duration, gridSize, waves, amplitude, horizontal, vertical) { 948 if (cc.Grid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) { 949 this._waves = waves; 950 this._amplitude = amplitude; 951 this._amplitudeRate = 1.0; 952 this._horizontal = horizontal; 953 this._vertical = vertical; 954 return true; 955 } 956 return false; 957 }, 958 959 update:function (time) { 960 var locSizeWidth = this._gridSize.width, locSizeHeight = this._gridSize.height, locPos = cc.p(0, 0); 961 var locVertical = this._vertical, locHorizontal = this._horizontal; 962 var locWaves = this._waves, locAmplitude = this._amplitude, locAmplitudeRate = this._amplitudeRate; 963 var v; 964 for (var i = 0; i < locSizeWidth + 1; ++i) { 965 for (var j = 0; j < locSizeHeight + 1; ++j) { 966 locPos.x = i; 967 locPos.y = j; 968 v = this.originalVertex(locPos); 969 if (locVertical) 970 v.x = (v.x + (Math.sin(time * Math.PI * locWaves * 2 + v.y * .01) * locAmplitude * locAmplitudeRate)); 971 if (locHorizontal) 972 v.y = (v.y + (Math.sin(time * Math.PI * locWaves * 2 + v.x * .01) * locAmplitude * locAmplitudeRate)); 973 this.setVertex(locPos, v); 974 } 975 } 976 } 977 }); 978 979 /** 980 * initializes the action with amplitude, horizontal sin, vertical sin, a grid and duration 981 * @function 982 * @param {Number} duration 983 * @param {cc.Size} gridSize 984 * @param {Number} waves 985 * @param {Number} amplitude 986 * @param {Boolean} horizontal 987 * @param {Boolean} vertical 988 * @return {cc.Waves} 989 */ 990 cc.waves = function (duration, gridSize, waves, amplitude, horizontal, vertical) { 991 return new cc.Waves(duration, gridSize, waves, amplitude, horizontal, vertical); 992 }; 993 994 /** 995 * Please use cc.waves instead 996 * initializes the action with amplitude, horizontal sin, vertical sin, a grid and duration 997 * @param {Number} duration 998 * @param {cc.Size} gridSize 999 * @param {Number} waves 1000 * @param {Number} amplitude 1001 * @param {Boolean} horizontal 1002 * @param {Boolean} vertical 1003 * @return {cc.Waves} 1004 * @static 1005 * @deprecated 1006 */ 1007 cc.Waves.create = cc.waves; 1008 1009 /** @brief */ 1010 /** 1011 * cc.Twirl action 1012 * @class 1013 * @extends cc.Grid3DAction 1014 */ 1015 cc.Twirl = cc.Grid3DAction.extend(/** @lends cc.Twirl# */{ 1016 /* twirl center */ 1017 _position: null, 1018 _twirls: 0, 1019 _amplitude: 0, 1020 _amplitudeRate: 0, 1021 1022 /** 1023 * Create a grid 3d action with center position, number of twirls, amplitude, a grid size and duration 1024 * Constructor of cc.Twirl 1025 * @param {Number} duration 1026 * @param {cc.Size} gridSize 1027 * @param {cc.Point} position 1028 * @param {Number} twirls 1029 * @param {Number} amplitude 1030 */ 1031 ctor:function (duration, gridSize, position, twirls, amplitude) { 1032 cc.GridAction.prototype.ctor.call(this); 1033 1034 this._position = cc.p(0, 0); 1035 amplitude !== undefined && this.initWithDuration(duration, gridSize, position, twirls, amplitude); 1036 }, 1037 1038 /** 1039 * get twirl center 1040 * @return {cc.Point} 1041 */ 1042 getPosition:function () { 1043 return this._position; 1044 }, 1045 1046 /** 1047 * set twirl center 1048 * @param {cc.Point} position 1049 */ 1050 setPosition:function (position) { 1051 this._position.x = position.x; 1052 this._position.y = position.y; 1053 }, 1054 1055 /** 1056 * get amplitude 1057 * @return {Number} 1058 */ 1059 getAmplitude:function () { 1060 return this._amplitude; 1061 }, 1062 1063 /** 1064 * set amplitude 1065 * @param {Number} amplitude 1066 */ 1067 setAmplitude:function (amplitude) { 1068 this._amplitude = amplitude; 1069 }, 1070 1071 /** 1072 * get amplitude rate 1073 * @return {Number} 1074 */ 1075 getAmplitudeRate:function () { 1076 return this._amplitudeRate; 1077 }, 1078 1079 /** 1080 * set amplitude rate 1081 * @param {Number} amplitudeRate 1082 */ 1083 setAmplitudeRate:function (amplitudeRate) { 1084 this._amplitudeRate = amplitudeRate; 1085 }, 1086 1087 /** initializes the action with center position, number of twirls, amplitude, a grid size and duration */ 1088 initWithDuration:function (duration, gridSize, position, twirls, amplitude) { 1089 if (cc.Grid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) { 1090 this.setPosition(position); 1091 this._twirls = twirls; 1092 this._amplitude = amplitude; 1093 this._amplitudeRate = 1.0; 1094 return true; 1095 } 1096 return false; 1097 }, 1098 1099 update:function (time) { 1100 var c = this._position; 1101 var locSizeWidth = this._gridSize.width, locSizeHeight = this._gridSize.height, locPos = cc.p(0, 0); 1102 var amp = 0.1 * this._amplitude * this._amplitudeRate; 1103 var locTwirls = this._twirls; 1104 var v, a, dX, dY, avg = cc.p(0, 0); 1105 for (var i = 0; i < (locSizeWidth + 1); ++i) { 1106 for (var j = 0; j < (locSizeHeight + 1); ++j) { 1107 locPos.x = i; 1108 locPos.y = j; 1109 v = this.originalVertex(locPos); 1110 1111 avg.x = i - (locSizeWidth / 2.0); 1112 avg.y = j - (locSizeHeight / 2.0); 1113 1114 a = cc.pLength(avg) * Math.cos(Math.PI / 2.0 + time * Math.PI * locTwirls * 2) * amp; 1115 1116 dX = Math.sin(a) * (v.y - c.y) + Math.cos(a) * (v.x - c.x); 1117 dY = Math.cos(a) * (v.y - c.y) - Math.sin(a) * (v.x - c.x); 1118 1119 v.x = c.x + dX; 1120 v.y = c.y + dY; 1121 1122 this.setVertex(locPos, v); 1123 } 1124 } 1125 } 1126 }); 1127 1128 /** 1129 * creates the action with center position, number of twirls, amplitude, a grid size and duration 1130 * @function 1131 * @param {Number} duration 1132 * @param {cc.Size} gridSize 1133 * @param {cc.Point} position 1134 * @param {Number} twirls 1135 * @param {Number} amplitude 1136 * @return {cc.Twirl} 1137 */ 1138 cc.twirl = function (duration, gridSize, position, twirls, amplitude) { 1139 return new cc.Twirl(duration, gridSize, position, twirls, amplitude); 1140 }; 1141 1142 /** 1143 * Please use cc.twirl instead 1144 * creates the action with center position, number of twirls, amplitude, a grid size and duration 1145 * @param {Number} duration 1146 * @param {cc.Size} gridSize 1147 * @param {cc.Point} position 1148 * @param {Number} twirls 1149 * @param {Number} amplitude 1150 * @return {cc.Twirl} 1151 * @static 1152 * @deprecated 1153 */ 1154 cc.Twirl.create = cc.twirl;