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 * <p> An interval action is an action that takes place within a certain period of time. <br/> 29 * It has an start time, and a finish time. The finish time is the parameter<br/> 30 * duration plus the start time.</p> 31 * 32 * <p>These CCActionInterval actions have some interesting properties, like:<br/> 33 * - They can run normally (default) <br/> 34 * - They can run reversed with the reverse method <br/> 35 * - They can run with the time altered with the Accelerate, AccelDeccel and Speed actions. </p> 36 * 37 * <p>For example, you can simulate a Ping Pong effect running the action normally and<br/> 38 * then running it again in Reverse mode. </p> 39 * 40 * @class 41 * @extends cc.FiniteTimeAction 42 * @param {Number} d duration in seconds 43 * @example 44 * var actionInterval = new cc.ActionInterval(3); 45 */ 46 cc.ActionInterval = cc.FiniteTimeAction.extend(/** @lends cc.ActionInterval# */{ 47 _elapsed:0, 48 _firstTick:false, 49 _easeList: null, 50 _timesForRepeat:1, 51 _repeatForever: false, 52 _repeatMethod: false,//Compatible with repeat class, Discard after can be deleted 53 _speed: 1, 54 _speedMethod: false,//Compatible with speed class, Discard after can be deleted 55 56 /** 57 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 58 * @param {Number} d duration in seconds 59 */ 60 ctor:function (d) { 61 this._speed = 1; 62 this._timesForRepeat = 1; 63 this._repeatForever = false; 64 this.MAX_VALUE = 2; 65 this._repeatMethod = false;//Compatible with repeat class, Discard after can be deleted 66 this._speedMethod = false;//Compatible with repeat class, Discard after can be deleted 67 cc.FiniteTimeAction.prototype.ctor.call(this); 68 d !== undefined && this.initWithDuration(d); 69 }, 70 71 /** 72 * How many seconds had elapsed since the actions started to run. 73 * @return {Number} 74 */ 75 getElapsed:function () { 76 return this._elapsed; 77 }, 78 79 /** 80 * Initializes the action. 81 * @param {Number} d duration in seconds 82 * @return {Boolean} 83 */ 84 initWithDuration:function (d) { 85 this._duration = (d === 0) ? cc.FLT_EPSILON : d; 86 // prevent division by 0 87 // This comparison could be in step:, but it might decrease the performance 88 // by 3% in heavy based action games. 89 this._elapsed = 0; 90 this._firstTick = true; 91 return true; 92 }, 93 94 /** 95 * Returns true if the action has finished. 96 * @return {Boolean} 97 */ 98 isDone:function () { 99 return (this._elapsed >= this._duration); 100 }, 101 102 /** 103 * Some additional parameters of cloning. 104 * @param {cc.Action} action 105 * @private 106 */ 107 _cloneDecoration: function(action){ 108 action._repeatForever = this._repeatForever; 109 action._speed = this._speed; 110 action._timesForRepeat = this._timesForRepeat; 111 action._easeList = this._easeList; 112 action._speedMethod = this._speedMethod; 113 action._repeatMethod = this._repeatMethod; 114 }, 115 116 _reverseEaseList: function(action){ 117 if(this._easeList){ 118 action._easeList = []; 119 for(var i=0; i<this._easeList.length; i++){ 120 action._easeList.push(this._easeList[i].reverse()); 121 } 122 } 123 }, 124 125 /** 126 * Returns a new clone of the action. 127 * @returns {cc.ActionInterval} 128 */ 129 clone:function () { 130 var action = new cc.ActionInterval(this._duration); 131 this._cloneDecoration(action); 132 return action; 133 }, 134 135 /** 136 * Implementation of ease motion. 137 * 138 * @example 139 * //example 140 * action.easeing(cc.easeIn(3.0)); 141 * @param {Object} easeObj 142 * @returns {cc.ActionInterval} 143 */ 144 easing: function (easeObj) { 145 if (this._easeList) 146 this._easeList.length = 0; 147 else 148 this._easeList = []; 149 for (var i = 0; i < arguments.length; i++) 150 this._easeList.push(arguments[i]); 151 return this; 152 }, 153 154 _computeEaseTime: function (dt) { 155 var locList = this._easeList; 156 if ((!locList) || (locList.length === 0)) 157 return dt; 158 for (var i = 0, n = locList.length; i < n; i++) 159 dt = locList[i].easing(dt); 160 return dt; 161 }, 162 163 /** 164 * called every frame with it's delta time. <br /> 165 * DON'T override unless you know what you are doing. 166 * 167 * @param {Number} dt 168 */ 169 step:function (dt) { 170 if (this._firstTick) { 171 this._firstTick = false; 172 this._elapsed = 0; 173 } else 174 this._elapsed += dt; 175 176 //this.update((1 > (this._elapsed / this._duration)) ? this._elapsed / this._duration : 1); 177 //this.update(Math.max(0, Math.min(1, this._elapsed / Math.max(this._duration, cc.FLT_EPSILON)))); 178 var t = this._elapsed / (this._duration > 0.0000001192092896 ? this._duration : 0.0000001192092896); 179 t = (1 > t ? t : 1); 180 this.update(t > 0 ? t : 0); 181 182 //Compatible with repeat class, Discard after can be deleted (this._repeatMethod) 183 if(this._repeatMethod && this._timesForRepeat > 1 && this.isDone()){ 184 if(!this._repeatForever){ 185 this._timesForRepeat--; 186 } 187 //var diff = locInnerAction.getElapsed() - locInnerAction._duration; 188 this.startWithTarget(this.target); 189 // to prevent jerk. issue #390 ,1247 190 //this._innerAction.step(0); 191 //this._innerAction.step(diff); 192 this.step(this._elapsed - this._duration); 193 194 } 195 }, 196 197 /** 198 * Start this action with target. 199 * @param {cc.Node} target 200 */ 201 startWithTarget:function (target) { 202 cc.Action.prototype.startWithTarget.call(this, target); 203 this._elapsed = 0; 204 this._firstTick = true; 205 }, 206 207 /** 208 * returns a reversed action. <br /> 209 * Will be overwrite. 210 * 211 * @return {?cc.Action} 212 */ 213 reverse:function () { 214 cc.log("cc.IntervalAction: reverse not implemented."); 215 return null; 216 }, 217 218 /** 219 * Set amplitude rate. 220 * @warning It should be overridden in subclass. 221 * @param {Number} amp 222 */ 223 setAmplitudeRate:function (amp) { 224 // Abstract class needs implementation 225 cc.log("cc.ActionInterval.setAmplitudeRate(): it should be overridden in subclass."); 226 }, 227 228 /** 229 * Get amplitude rate. 230 * @warning It should be overridden in subclass. 231 * @return {Number} 0 232 */ 233 getAmplitudeRate:function () { 234 // Abstract class needs implementation 235 cc.log("cc.ActionInterval.getAmplitudeRate(): it should be overridden in subclass."); 236 return 0; 237 }, 238 239 /** 240 * Changes the speed of an action, making it take longer (speed>1) 241 * or less (speed<1) time. <br/> 242 * Useful to simulate 'slow motion' or 'fast forward' effect. 243 * 244 * @param speed 245 * @returns {cc.Action} 246 */ 247 speed: function(speed){ 248 if(speed <= 0){ 249 cc.log("The speed parameter error"); 250 return this; 251 } 252 253 this._speedMethod = true;//Compatible with repeat class, Discard after can be deleted 254 this._speed *= speed; 255 return this; 256 }, 257 258 /** 259 * Get this action speed. 260 * @return {Number} 261 */ 262 getSpeed: function(){ 263 return this._speed; 264 }, 265 266 /** 267 * Set this action speed. 268 * @param {Number} speed 269 * @returns {cc.ActionInterval} 270 */ 271 setSpeed: function(speed){ 272 this._speed = speed; 273 return this; 274 }, 275 276 /** 277 * Repeats an action a number of times. 278 * To repeat an action forever use the CCRepeatForever action. 279 * @param times 280 * @returns {cc.ActionInterval} 281 */ 282 repeat: function(times){ 283 times = Math.round(times); 284 if(isNaN(times) || times < 1){ 285 cc.log("The repeat parameter error"); 286 return this; 287 } 288 this._repeatMethod = true;//Compatible with repeat class, Discard after can be deleted 289 this._timesForRepeat *= times; 290 return this; 291 }, 292 293 /** 294 * Repeats an action for ever. <br/> 295 * To repeat the an action for a limited number of times use the Repeat action. <br/> 296 * @returns {cc.ActionInterval} 297 */ 298 repeatForever: function(){ 299 this._repeatMethod = true;//Compatible with repeat class, Discard after can be deleted 300 this._timesForRepeat = this.MAX_VALUE; 301 this._repeatForever = true; 302 return this; 303 } 304 }); 305 306 /** 307 * An interval action is an action that takes place within a certain period of time. 308 * @function 309 * @param {Number} d duration in seconds 310 * @return {cc.ActionInterval} 311 * @example 312 * // example 313 * var actionInterval = cc.actionInterval(3); 314 */ 315 cc.actionInterval = function (d) { 316 return new cc.ActionInterval(d); 317 }; 318 319 /** 320 * Please use cc.actionInterval instead. 321 * An interval action is an action that takes place within a certain period of time. 322 * @static 323 * @deprecated since v3.0 <br /> Please use cc.actionInterval instead. 324 * @param {Number} d duration in seconds 325 * @return {cc.ActionInterval} 326 */ 327 cc.ActionInterval.create = cc.actionInterval; 328 329 /** 330 * Runs actions sequentially, one after another. 331 * @class 332 * @extends cc.ActionInterval 333 * @param {Array|cc.FiniteTimeAction} tempArray 334 * @example 335 * // create sequence with actions 336 * var seq = new cc.Sequence(act1, act2); 337 * 338 * // create sequence with array 339 * var seq = new cc.Sequence(actArray); 340 */ 341 cc.Sequence = cc.ActionInterval.extend(/** @lends cc.Sequence# */{ 342 _actions:null, 343 _split:null, 344 _last:0, 345 346 /** 347 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br /> 348 * Create an array of sequenceable actions. 349 * @param {Array|cc.FiniteTimeAction} tempArray 350 */ 351 ctor:function (tempArray) { 352 cc.ActionInterval.prototype.ctor.call(this); 353 this._actions = []; 354 355 var paramArray = (tempArray instanceof Array) ? tempArray : arguments; 356 var last = paramArray.length - 1; 357 if ((last >= 0) && (paramArray[last] == null)) 358 cc.log("parameters should not be ending with null in Javascript"); 359 360 if (last >= 0) { 361 var prev = paramArray[0], action1; 362 for (var i = 1; i < last; i++) { 363 if (paramArray[i]) { 364 action1 = prev; 365 prev = cc.Sequence._actionOneTwo(action1, paramArray[i]); 366 } 367 } 368 this.initWithTwoActions(prev, paramArray[last]); 369 } 370 }, 371 372 /** 373 * Initializes the action <br/> 374 * @param {cc.FiniteTimeAction} actionOne 375 * @param {cc.FiniteTimeAction} actionTwo 376 * @return {Boolean} 377 */ 378 initWithTwoActions:function (actionOne, actionTwo) { 379 if(!actionOne || !actionTwo) 380 throw new Error("cc.Sequence.initWithTwoActions(): arguments must all be non nil"); 381 382 var d = actionOne._duration + actionTwo._duration; 383 this.initWithDuration(d); 384 385 this._actions[0] = actionOne; 386 this._actions[1] = actionTwo; 387 return true; 388 }, 389 390 /** 391 * returns a new clone of the action 392 * @returns {cc.Sequence} 393 */ 394 clone:function () { 395 var action = new cc.Sequence(); 396 this._cloneDecoration(action); 397 action.initWithTwoActions(this._actions[0].clone(), this._actions[1].clone()); 398 return action; 399 }, 400 401 /** 402 * Start the action with target. 403 * @param {cc.Node} target 404 */ 405 startWithTarget:function (target) { 406 cc.ActionInterval.prototype.startWithTarget.call(this, target); 407 this._split = this._actions[0]._duration / this._duration; 408 this._last = -1; 409 }, 410 411 /** 412 * stop the action. 413 */ 414 stop:function () { 415 // Issue #1305 416 if (this._last !== -1) 417 this._actions[this._last].stop(); 418 cc.Action.prototype.stop.call(this); 419 }, 420 421 /** 422 * Called once per frame. Time is the number of seconds of a frame interval. 423 * @param {Number} dt 424 */ 425 update:function (dt) { 426 var new_t, found = 0; 427 var locSplit = this._split, locActions = this._actions, locLast = this._last, actionFound; 428 429 dt = this._computeEaseTime(dt); 430 if (dt < locSplit) { 431 // action[0] 432 new_t = (locSplit !== 0) ? dt / locSplit : 1; 433 434 if (found === 0 && locLast === 1) { 435 // Reverse mode ? 436 // XXX: Bug. this case doesn't contemplate when _last==-1, found=0 and in "reverse mode" 437 // since it will require a hack to know if an action is on reverse mode or not. 438 // "step" should be overriden, and the "reverseMode" value propagated to inner Sequences. 439 locActions[1].update(0); 440 locActions[1].stop(); 441 } 442 } else { 443 // action[1] 444 found = 1; 445 new_t = (locSplit === 1) ? 1 : (dt - locSplit) / (1 - locSplit); 446 447 if (locLast === -1) { 448 // action[0] was skipped, execute it. 449 locActions[0].startWithTarget(this.target); 450 locActions[0].update(1); 451 locActions[0].stop(); 452 } 453 if (!locLast) { 454 // switching to action 1. stop action 0. 455 locActions[0].update(1); 456 locActions[0].stop(); 457 } 458 } 459 460 actionFound = locActions[found]; 461 // Last action found and it is done. 462 if (locLast === found && actionFound.isDone()) 463 return; 464 465 // Last action found and it is done 466 if (locLast !== found) 467 actionFound.startWithTarget(this.target); 468 469 new_t = new_t * actionFound._timesForRepeat; 470 actionFound.update(new_t > 1 ? new_t % 1 : new_t); 471 this._last = found; 472 }, 473 474 /** 475 * Returns a reversed action. 476 * @return {cc.Sequence} 477 */ 478 reverse:function () { 479 var action = cc.Sequence._actionOneTwo(this._actions[1].reverse(), this._actions[0].reverse()); 480 this._cloneDecoration(action); 481 this._reverseEaseList(action); 482 return action; 483 } 484 }); 485 486 /** helper constructor to create an array of sequenceable actions 487 * @function 488 * @param {Array|cc.FiniteTimeAction} tempArray 489 * @return {cc.Sequence} 490 * @example 491 * // example 492 * // create sequence with actions 493 * var seq = cc.sequence(act1, act2); 494 * 495 * // create sequence with array 496 * var seq = cc.sequence(actArray); 497 * todo: It should be use new 498 */ 499 cc.sequence = function (/*Multiple Arguments*/tempArray) { 500 var paramArray = (tempArray instanceof Array) ? tempArray : arguments; 501 if ((paramArray.length > 0) && (paramArray[paramArray.length - 1] == null)) 502 cc.log("parameters should not be ending with null in Javascript"); 503 504 var result, current, i, repeat; 505 while(paramArray && paramArray.length > 0){ 506 current = Array.prototype.shift.call(paramArray); 507 repeat = current._timesForRepeat || 1; 508 current._repeatMethod = false; 509 current._timesForRepeat = 1; 510 511 i = 0; 512 if(!result){ 513 result = current; 514 i = 1; 515 } 516 517 for(i; i<repeat; i++){ 518 result = cc.Sequence._actionOneTwo(result, current); 519 } 520 } 521 522 return result; 523 }; 524 525 /** 526 * Please use cc.sequence instead. 527 * helper constructor to create an array of sequenceable actions 528 * @static 529 * @deprecated since v3.0 <br /> Please use cc.sequence instead. 530 * @param {Array|cc.FiniteTimeAction} tempArray 531 * @return {cc.Sequence} 532 */ 533 cc.Sequence.create = cc.sequence; 534 535 /** creates the action 536 * @param {cc.FiniteTimeAction} actionOne 537 * @param {cc.FiniteTimeAction} actionTwo 538 * @return {cc.Sequence} 539 * @private 540 */ 541 cc.Sequence._actionOneTwo = function (actionOne, actionTwo) { 542 var sequence = new cc.Sequence(); 543 sequence.initWithTwoActions(actionOne, actionTwo); 544 return sequence; 545 }; 546 547 /** 548 * Repeats an action a number of times. 549 * To repeat an action forever use the CCRepeatForever action. 550 * @class 551 * @extends cc.ActionInterval 552 * @param {cc.FiniteTimeAction} action 553 * @param {Number} times 554 * @example 555 * var rep = new cc.Repeat(cc.sequence(jump2, jump1), 5); 556 */ 557 cc.Repeat = cc.ActionInterval.extend(/** @lends cc.Repeat# */{ 558 _times:0, 559 _total:0, 560 _nextDt:0, 561 _actionInstant:false, 562 _innerAction:null, //CCFiniteTimeAction 563 564 /** 565 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br /> 566 * Creates a Repeat action. Times is an unsigned integer between 1 and pow(2,30). 567 * @param {cc.FiniteTimeAction} action 568 * @param {Number} times 569 */ 570 ctor: function (action, times) { 571 cc.ActionInterval.prototype.ctor.call(this); 572 573 times !== undefined && this.initWithAction(action, times); 574 }, 575 576 /** 577 * @param {cc.FiniteTimeAction} action 578 * @param {Number} times 579 * @return {Boolean} 580 */ 581 initWithAction:function (action, times) { 582 var duration = action._duration * times; 583 584 if (this.initWithDuration(duration)) { 585 this._times = times; 586 this._innerAction = action; 587 if (action instanceof cc.ActionInstant){ 588 this._actionInstant = true; 589 this._times -= 1; 590 } 591 this._total = 0; 592 return true; 593 } 594 return false; 595 }, 596 597 /** 598 * returns a new clone of the action 599 * @returns {cc.Repeat} 600 */ 601 clone:function () { 602 var action = new cc.Repeat(); 603 this._cloneDecoration(action); 604 action.initWithAction(this._innerAction.clone(), this._times); 605 return action; 606 }, 607 608 /** 609 * Start the action with target. 610 * @param {cc.Node} target 611 */ 612 startWithTarget:function (target) { 613 this._total = 0; 614 this._nextDt = this._innerAction._duration / this._duration; 615 cc.ActionInterval.prototype.startWithTarget.call(this, target); 616 this._innerAction.startWithTarget(target); 617 }, 618 619 /** 620 * stop the action 621 */ 622 stop:function () { 623 this._innerAction.stop(); 624 cc.Action.prototype.stop.call(this); 625 }, 626 627 /** 628 * Called once per frame. Time is the number of seconds of a frame interval. 629 * @param {Number} dt 630 */ 631 update:function (dt) { 632 dt = this._computeEaseTime(dt); 633 var locInnerAction = this._innerAction; 634 var locDuration = this._duration; 635 var locTimes = this._times; 636 var locNextDt = this._nextDt; 637 638 if (dt >= locNextDt) { 639 while (dt > locNextDt && this._total < locTimes) { 640 locInnerAction.update(1); 641 this._total++; 642 locInnerAction.stop(); 643 locInnerAction.startWithTarget(this.target); 644 locNextDt += locInnerAction._duration / locDuration; 645 this._nextDt = locNextDt; 646 } 647 648 // fix for issue #1288, incorrect end value of repeat 649 if (dt >= 1.0 && this._total < locTimes) 650 this._total++; 651 652 // don't set a instant action back or update it, it has no use because it has no duration 653 if (!this._actionInstant) { 654 if (this._total === locTimes) { 655 locInnerAction.update(1); 656 locInnerAction.stop(); 657 } else { 658 // issue #390 prevent jerk, use right update 659 locInnerAction.update(dt - (locNextDt - locInnerAction._duration / locDuration)); 660 } 661 } 662 } else { 663 locInnerAction.update((dt * locTimes) % 1.0); 664 } 665 }, 666 667 /** 668 * Return true if the action has finished. 669 * @return {Boolean} 670 */ 671 isDone:function () { 672 return this._total === this._times; 673 }, 674 675 /** 676 * returns a reversed action. 677 * @return {cc.Repeat} 678 */ 679 reverse:function () { 680 var action = new cc.Repeat(this._innerAction.reverse(), this._times); 681 this._cloneDecoration(action); 682 this._reverseEaseList(action); 683 return action; 684 }, 685 686 /** 687 * Set inner Action. 688 * @param {cc.FiniteTimeAction} action 689 */ 690 setInnerAction:function (action) { 691 if (this._innerAction !== action) { 692 this._innerAction = action; 693 } 694 }, 695 696 /** 697 * Get inner Action. 698 * @return {cc.FiniteTimeAction} 699 */ 700 getInnerAction:function () { 701 return this._innerAction; 702 } 703 }); 704 705 /** 706 * Creates a Repeat action. Times is an unsigned integer between 1 and pow(2,30) 707 * @function 708 * @param {cc.FiniteTimeAction} action 709 * @param {Number} times 710 * @return {cc.Repeat} 711 * @example 712 * // example 713 * var rep = cc.repeat(cc.sequence(jump2, jump1), 5); 714 */ 715 cc.repeat = function (action, times) { 716 return new cc.Repeat(action, times); 717 }; 718 719 /** 720 * Please use cc.repeat instead 721 * Creates a Repeat action. Times is an unsigned integer between 1 and pow(2,30) 722 * @static 723 * @deprecated since v3.0 <br /> Please use cc.repeat instead. 724 * @param {cc.FiniteTimeAction} action 725 * @param {Number} times 726 * @return {cc.Repeat} 727 */ 728 cc.Repeat.create = cc.repeat; 729 730 731 /** Repeats an action for ever. <br/> 732 * To repeat the an action for a limited number of times use the Repeat action. <br/> 733 * @warning This action can't be Sequenceable because it is not an IntervalAction 734 * @class 735 * @extends cc.ActionInterval 736 * @param {cc.FiniteTimeAction} action 737 * @example 738 * var rep = new cc.RepeatForever(cc.sequence(jump2, jump1), 5); 739 */ 740 cc.RepeatForever = cc.ActionInterval.extend(/** @lends cc.RepeatForever# */{ 741 _innerAction:null, //CCActionInterval 742 743 /** 744 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br /> 745 * Create a acton which repeat forever. 746 * @param {cc.FiniteTimeAction} action 747 */ 748 ctor:function (action) { 749 cc.ActionInterval.prototype.ctor.call(this); 750 this._innerAction = null; 751 752 action && this.initWithAction(action); 753 }, 754 755 /** 756 * @param {cc.ActionInterval} action 757 * @return {Boolean} 758 */ 759 initWithAction:function (action) { 760 if(!action) 761 throw new Error("cc.RepeatForever.initWithAction(): action must be non null"); 762 763 this._innerAction = action; 764 return true; 765 }, 766 767 /** 768 * returns a new clone of the action 769 * @returns {cc.RepeatForever} 770 */ 771 clone:function () { 772 var action = new cc.RepeatForever(); 773 this._cloneDecoration(action); 774 action.initWithAction(this._innerAction.clone()); 775 return action; 776 }, 777 778 /** 779 * Start the action with target. 780 * @param {cc.Node} target 781 */ 782 startWithTarget:function (target) { 783 cc.ActionInterval.prototype.startWithTarget.call(this, target); 784 this._innerAction.startWithTarget(target); 785 }, 786 787 /** 788 * called every frame with it's delta time. <br /> 789 * DON'T override unless you know what you are doing. 790 * @param dt delta time in seconds 791 */ 792 step:function (dt) { 793 var locInnerAction = this._innerAction; 794 locInnerAction.step(dt); 795 if (locInnerAction.isDone()) { 796 //var diff = locInnerAction.getElapsed() - locInnerAction._duration; 797 locInnerAction.startWithTarget(this.target); 798 // to prevent jerk. issue #390 ,1247 799 //this._innerAction.step(0); 800 //this._innerAction.step(diff); 801 locInnerAction.step(locInnerAction.getElapsed() - locInnerAction._duration); 802 } 803 }, 804 805 /** 806 * Return true if the action has finished. 807 * @return {Boolean} 808 */ 809 isDone:function () { 810 return false; 811 }, 812 813 /** 814 * Returns a reversed action. 815 * @return {cc.RepeatForever} 816 */ 817 reverse:function () { 818 var action = new cc.RepeatForever(this._innerAction.reverse()); 819 this._cloneDecoration(action); 820 this._reverseEaseList(action); 821 return action; 822 }, 823 824 /** 825 * Set inner action. 826 * @param {cc.ActionInterval} action 827 */ 828 setInnerAction:function (action) { 829 if (this._innerAction !== action) { 830 this._innerAction = action; 831 } 832 }, 833 834 /** 835 * Get inner action. 836 * @return {cc.ActionInterval} 837 */ 838 getInnerAction:function () { 839 return this._innerAction; 840 } 841 }); 842 843 /** 844 * Create a acton which repeat forever 845 * @function 846 * @param {cc.FiniteTimeAction} action 847 * @return {cc.RepeatForever} 848 * @example 849 * // example 850 * var repeat = cc.repeatForever(cc.rotateBy(1.0, 360)); 851 */ 852 cc.repeatForever = function (action) { 853 return new cc.RepeatForever(action); 854 }; 855 856 /** 857 * Please use cc.repeatForever instead 858 * Create a acton which repeat forever 859 * @static 860 * @deprecated since v3.0 <br /> Please use cc.repeatForever instead. 861 * @param {cc.FiniteTimeAction} action 862 * @return {cc.RepeatForever} 863 * @param {Array|cc.FiniteTimeAction} tempArray 864 * @example 865 * var action = new cc.Spawn(cc.jumpBy(2, cc.p(300, 0), 50, 4), cc.rotateBy(2, 720)); 866 */ 867 cc.RepeatForever.create = cc.repeatForever; 868 869 870 /** Spawn a new action immediately 871 * @class 872 * @extends cc.ActionInterval 873 */ 874 cc.Spawn = cc.ActionInterval.extend(/** @lends cc.Spawn# */{ 875 _one:null, 876 _two:null, 877 878 /** 879 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 880 * @param {Array|cc.FiniteTimeAction} tempArray 881 */ 882 ctor:function (tempArray) { 883 cc.ActionInterval.prototype.ctor.call(this); 884 this._one = null; 885 this._two = null; 886 887 var paramArray = (tempArray instanceof Array) ? tempArray : arguments; 888 var last = paramArray.length - 1; 889 if ((last >= 0) && (paramArray[last] == null)) 890 cc.log("parameters should not be ending with null in Javascript"); 891 892 if (last >= 0) { 893 var prev = paramArray[0], action1; 894 for (var i = 1; i < last; i++) { 895 if (paramArray[i]) { 896 action1 = prev; 897 prev = cc.Spawn._actionOneTwo(action1, paramArray[i]); 898 } 899 } 900 this.initWithTwoActions(prev, paramArray[last]); 901 } 902 }, 903 904 /** initializes the Spawn action with the 2 actions to spawn 905 * @param {cc.FiniteTimeAction} action1 906 * @param {cc.FiniteTimeAction} action2 907 * @return {Boolean} 908 */ 909 initWithTwoActions:function (action1, action2) { 910 if(!action1 || !action2) 911 throw new Error("cc.Spawn.initWithTwoActions(): arguments must all be non null"); 912 913 var ret = false; 914 915 var d1 = action1._duration; 916 var d2 = action2._duration; 917 918 if (this.initWithDuration(Math.max(d1, d2))) { 919 this._one = action1; 920 this._two = action2; 921 922 if (d1 > d2) { 923 this._two = cc.Sequence._actionOneTwo(action2, cc.delayTime(d1 - d2)); 924 } else if (d1 < d2) { 925 this._one = cc.Sequence._actionOneTwo(action1, cc.delayTime(d2 - d1)); 926 } 927 928 ret = true; 929 } 930 return ret; 931 }, 932 933 /** 934 * returns a new clone of the action 935 * @returns {cc.Spawn} 936 */ 937 clone:function () { 938 var action = new cc.Spawn(); 939 this._cloneDecoration(action); 940 action.initWithTwoActions(this._one.clone(), this._two.clone()); 941 return action; 942 }, 943 944 /** 945 * Start the action with target. 946 * @param {cc.Node} target 947 */ 948 startWithTarget:function (target) { 949 cc.ActionInterval.prototype.startWithTarget.call(this, target); 950 this._one.startWithTarget(target); 951 this._two.startWithTarget(target); 952 }, 953 954 /** 955 * Stop the action 956 */ 957 stop:function () { 958 this._one.stop(); 959 this._two.stop(); 960 cc.Action.prototype.stop.call(this); 961 }, 962 963 /** 964 * Called once per frame. Time is the number of seconds of a frame interval. 965 * @param {Number} dt 966 */ 967 update:function (dt) { 968 dt = this._computeEaseTime(dt); 969 if (this._one) 970 this._one.update(dt); 971 if (this._two) 972 this._two.update(dt); 973 }, 974 975 /** 976 * Returns a reversed action. 977 * @return {cc.Spawn} 978 */ 979 reverse:function () { 980 var action = cc.Spawn._actionOneTwo(this._one.reverse(), this._two.reverse()); 981 this._cloneDecoration(action); 982 this._reverseEaseList(action); 983 return action; 984 } 985 }); 986 987 /** 988 * Create a spawn action which runs several actions in parallel. 989 * @function 990 * @param {Array|cc.FiniteTimeAction}tempArray 991 * @return {cc.FiniteTimeAction} 992 * @example 993 * // example 994 * var action = cc.spawn(cc.jumpBy(2, cc.p(300, 0), 50, 4), cc.rotateBy(2, 720)); 995 * todo:It should be the direct use new 996 */ 997 cc.spawn = function (/*Multiple Arguments*/tempArray) { 998 var paramArray = (tempArray instanceof Array) ? tempArray : arguments; 999 if ((paramArray.length > 0) && (paramArray[paramArray.length - 1] == null)) 1000 cc.log("parameters should not be ending with null in Javascript"); 1001 1002 var prev = paramArray[0]; 1003 for (var i = 1; i < paramArray.length; i++) { 1004 if (paramArray[i] != null) 1005 prev = cc.Spawn._actionOneTwo(prev, paramArray[i]); 1006 } 1007 return prev; 1008 }; 1009 1010 /** 1011 * Please use cc.spawn instead. 1012 * Create a spawn action which runs several actions in parallel. 1013 * @static 1014 * @deprecated since v3.0 <br /> Please use cc.spawn instead. 1015 * @param {Array|cc.FiniteTimeAction}tempArray 1016 * @return {cc.FiniteTimeAction} 1017 */ 1018 cc.Spawn.create = cc.spawn; 1019 1020 /** 1021 * @param {cc.FiniteTimeAction} action1 1022 * @param {cc.FiniteTimeAction} action2 1023 * @return {cc.Spawn} 1024 * @private 1025 */ 1026 cc.Spawn._actionOneTwo = function (action1, action2) { 1027 var pSpawn = new cc.Spawn(); 1028 pSpawn.initWithTwoActions(action1, action2); 1029 return pSpawn; 1030 }; 1031 1032 1033 /** 1034 * Rotates a cc.Node object to a certain angle by modifying it's. 1035 * rotation attribute. <br/> 1036 * The direction will be decided by the shortest angle. 1037 * @class 1038 * @extends cc.ActionInterval 1039 * @param {Number} duration duration in seconds 1040 * @param {Number} deltaAngleX deltaAngleX in degrees. 1041 * @param {Number} [deltaAngleY] deltaAngleY in degrees. 1042 * @example 1043 * var rotateTo = new cc.RotateTo(2, 61.0); 1044 */ 1045 cc.RotateTo = cc.ActionInterval.extend(/** @lends cc.RotateTo# */{ 1046 _dstAngleX:0, 1047 _startAngleX:0, 1048 _diffAngleX:0, 1049 1050 _dstAngleY:0, 1051 _startAngleY:0, 1052 _diffAngleY:0, 1053 1054 /** 1055 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br /> 1056 * Creates a RotateTo action with x and y rotation angles. 1057 * @param {Number} duration duration in seconds 1058 * @param {Number} deltaAngleX deltaAngleX in degrees. 1059 * @param {Number} [deltaAngleY] deltaAngleY in degrees. 1060 */ 1061 ctor:function (duration, deltaAngleX, deltaAngleY) { 1062 cc.ActionInterval.prototype.ctor.call(this); 1063 1064 deltaAngleX !== undefined && this.initWithDuration(duration, deltaAngleX, deltaAngleY); 1065 }, 1066 1067 /** 1068 * Initializes the action. 1069 * @param {Number} duration 1070 * @param {Number} deltaAngleX 1071 * @param {Number} deltaAngleY 1072 * @return {Boolean} 1073 */ 1074 initWithDuration:function (duration, deltaAngleX, deltaAngleY) { 1075 if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) { 1076 this._dstAngleX = deltaAngleX || 0; 1077 this._dstAngleY = deltaAngleY || this._dstAngleX; 1078 return true; 1079 } 1080 return false; 1081 }, 1082 1083 /** 1084 * returns a new clone of the action 1085 * @returns {cc.RotateTo} 1086 */ 1087 clone:function () { 1088 var action = new cc.RotateTo(); 1089 this._cloneDecoration(action); 1090 action.initWithDuration(this._duration, this._dstAngleX, this._dstAngleY); 1091 return action; 1092 }, 1093 1094 /** 1095 * Start the action with target. 1096 * @param {cc.Node} target 1097 */ 1098 startWithTarget:function (target) { 1099 cc.ActionInterval.prototype.startWithTarget.call(this, target); 1100 1101 // Calculate X 1102 var locStartAngleX = target.rotationX % 360.0; 1103 var locDiffAngleX = this._dstAngleX - locStartAngleX; 1104 if (locDiffAngleX > 180) 1105 locDiffAngleX -= 360; 1106 if (locDiffAngleX < -180) 1107 locDiffAngleX += 360; 1108 this._startAngleX = locStartAngleX; 1109 this._diffAngleX = locDiffAngleX; 1110 1111 // Calculate Y It's duplicated from calculating X since the rotation wrap should be the same 1112 this._startAngleY = target.rotationY % 360.0; 1113 var locDiffAngleY = this._dstAngleY - this._startAngleY; 1114 if (locDiffAngleY > 180) 1115 locDiffAngleY -= 360; 1116 if (locDiffAngleY < -180) 1117 locDiffAngleY += 360; 1118 this._diffAngleY = locDiffAngleY; 1119 }, 1120 1121 /** 1122 * RotateTo reverse not implemented. 1123 * Will be overridden. 1124 * @returns {cc.Action} 1125 */ 1126 reverse:function () { 1127 cc.log("cc.RotateTo.reverse(): it should be overridden in subclass."); 1128 }, 1129 1130 /** 1131 * Called once per frame. Time is the number of seconds of a frame interval. 1132 * @param {Number} dt 1133 */ 1134 update:function (dt) { 1135 dt = this._computeEaseTime(dt); 1136 if (this.target) { 1137 this.target.rotationX = this._startAngleX + this._diffAngleX * dt; 1138 this.target.rotationY = this._startAngleY + this._diffAngleY * dt; 1139 } 1140 } 1141 }); 1142 1143 /** 1144 * Creates a RotateTo action with separate rotation angles. 1145 * To specify the angle of rotation. 1146 * @function 1147 * @param {Number} duration duration in seconds 1148 * @param {Number} deltaAngleX deltaAngleX in degrees. 1149 * @param {Number} [deltaAngleY] deltaAngleY in degrees. 1150 * @return {cc.RotateTo} 1151 * @example 1152 * // example 1153 * var rotateTo = cc.rotateTo(2, 61.0); 1154 */ 1155 cc.rotateTo = function (duration, deltaAngleX, deltaAngleY) { 1156 return new cc.RotateTo(duration, deltaAngleX, deltaAngleY); 1157 }; 1158 1159 /** 1160 * Please use cc.rotateTo instead 1161 * Creates a RotateTo action with separate rotation angles. 1162 * To specify the angle of rotation. 1163 * @static 1164 * @deprecated since v3.0 <br /> Please use cc.rotateTo instead. 1165 * @param {Number} duration duration in seconds 1166 * @param {Number} deltaAngleX deltaAngleX in degrees. 1167 * @param {Number} [deltaAngleY] deltaAngleY in degrees. 1168 * @return {cc.RotateTo} 1169 */ 1170 cc.RotateTo.create = cc.rotateTo; 1171 1172 1173 /** 1174 * Rotates a cc.Node object clockwise a number of degrees by modifying it's rotation attribute. 1175 * Relative to its properties to modify. 1176 * @class 1177 * @extends cc.ActionInterval 1178 * @param {Number} duration duration in seconds 1179 * @param {Number} deltaAngleX deltaAngleX in degrees 1180 * @param {Number} [deltaAngleY] deltaAngleY in degrees 1181 * @example 1182 * var actionBy = new cc.RotateBy(2, 360); 1183 */ 1184 cc.RotateBy = cc.ActionInterval.extend(/** @lends cc.RotateBy# */{ 1185 _angleX:0, 1186 _startAngleX:0, 1187 _angleY:0, 1188 _startAngleY:0, 1189 1190 /** 1191 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 1192 * @param {Number} duration duration in seconds 1193 * @param {Number} deltaAngleX deltaAngleX in degrees 1194 * @param {Number} [deltaAngleY] deltaAngleY in degrees 1195 */ 1196 ctor: function (duration, deltaAngleX, deltaAngleY) { 1197 cc.ActionInterval.prototype.ctor.call(this); 1198 1199 deltaAngleX !== undefined && this.initWithDuration(duration, deltaAngleX, deltaAngleY); 1200 }, 1201 1202 /** 1203 * Initializes the action. 1204 * @param {Number} duration duration in seconds 1205 * @param {Number} deltaAngleX deltaAngleX in degrees 1206 * @param {Number} [deltaAngleY=] deltaAngleY in degrees 1207 * @return {Boolean} 1208 */ 1209 initWithDuration:function (duration, deltaAngleX, deltaAngleY) { 1210 if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) { 1211 this._angleX = deltaAngleX || 0; 1212 this._angleY = deltaAngleY || this._angleX; 1213 return true; 1214 } 1215 return false; 1216 }, 1217 1218 /** 1219 * returns a new clone of the action 1220 * @returns {cc.RotateBy} 1221 */ 1222 clone:function () { 1223 var action = new cc.RotateBy(); 1224 this._cloneDecoration(action); 1225 action.initWithDuration(this._duration, this._angleX, this._angleY); 1226 return action; 1227 }, 1228 1229 /** 1230 * Start the action with target. 1231 * @param {cc.Node} target 1232 */ 1233 startWithTarget:function (target) { 1234 cc.ActionInterval.prototype.startWithTarget.call(this, target); 1235 this._startAngleX = target.rotationX; 1236 this._startAngleY = target.rotationY; 1237 }, 1238 1239 /** 1240 * Called once per frame. Time is the number of seconds of a frame interval. 1241 * @param {Number} dt 1242 */ 1243 update:function (dt) { 1244 dt = this._computeEaseTime(dt); 1245 if (this.target) { 1246 this.target.rotationX = this._startAngleX + this._angleX * dt; 1247 this.target.rotationY = this._startAngleY + this._angleY * dt; 1248 } 1249 }, 1250 1251 /** 1252 * Returns a reversed action. 1253 * @return {cc.RotateBy} 1254 */ 1255 reverse:function () { 1256 var action = new cc.RotateBy(this._duration, -this._angleX, -this._angleY); 1257 this._cloneDecoration(action); 1258 this._reverseEaseList(action); 1259 return action; 1260 } 1261 }); 1262 1263 /** 1264 * Rotates a cc.Node object clockwise a number of degrees by modifying it's rotation attribute. 1265 * Relative to its properties to modify. 1266 * @function 1267 * @param {Number} duration duration in seconds 1268 * @param {Number} deltaAngleX deltaAngleX in degrees 1269 * @param {Number} [deltaAngleY] deltaAngleY in degrees 1270 * @return {cc.RotateBy} 1271 * @example 1272 * // example 1273 * var actionBy = cc.rotateBy(2, 360); 1274 */ 1275 cc.rotateBy = function (duration, deltaAngleX, deltaAngleY) { 1276 return new cc.RotateBy(duration, deltaAngleX, deltaAngleY); 1277 }; 1278 /** 1279 * Please use cc.rotateBy instead. 1280 * Rotates a cc.Node object clockwise a number of degrees by modifying it's rotation attribute. 1281 * Relative to its properties to modify. 1282 * @static 1283 * @deprecated since v3.0 <br /> Please use cc.rotateBy instead. 1284 * @param {Number} duration duration in seconds 1285 * @param {Number} deltaAngleX deltaAngleX in degrees 1286 * @param {Number} [deltaAngleY] deltaAngleY in degrees 1287 * @return {cc.RotateBy} 1288 */ 1289 cc.RotateBy.create = cc.rotateBy; 1290 1291 1292 /** 1293 * <p> 1294 * Moves a CCNode object x,y pixels by modifying it's position attribute. <br/> 1295 * x and y are relative to the position of the object. <br/> 1296 * Several CCMoveBy actions can be concurrently called, and the resulting <br/> 1297 * movement will be the sum of individual movements. 1298 * </p> 1299 * @class 1300 * @extends cc.ActionInterval 1301 * @param {Number} duration duration in seconds 1302 * @param {cc.Point|Number} deltaPos 1303 * @param {Number} [deltaY] 1304 * @example 1305 * var actionTo = cc.moveBy(2, cc.p(windowSize.width - 40, windowSize.height - 40)); 1306 */ 1307 cc.MoveBy = cc.ActionInterval.extend(/** @lends cc.MoveBy# */{ 1308 _positionDelta:null, 1309 _startPosition:null, 1310 _previousPosition:null, 1311 1312 /** 1313 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 1314 * @param {Number} duration duration in seconds 1315 * @param {cc.Point|Number} deltaPos 1316 * @param {Number} [deltaY] 1317 */ 1318 ctor:function (duration, deltaPos, deltaY) { 1319 cc.ActionInterval.prototype.ctor.call(this); 1320 1321 this._positionDelta = cc.p(0, 0); 1322 this._startPosition = cc.p(0, 0); 1323 this._previousPosition = cc.p(0, 0); 1324 1325 deltaPos !== undefined && this.initWithDuration(duration, deltaPos, deltaY); 1326 }, 1327 1328 /** 1329 * Initializes the action. 1330 * @param {Number} duration duration in seconds 1331 * @param {cc.Point} position 1332 * @param {Number} [y] 1333 * @return {Boolean} 1334 */ 1335 initWithDuration:function (duration, position, y) { 1336 if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) { 1337 if(position.x !== undefined) { 1338 y = position.y; 1339 position = position.x; 1340 } 1341 1342 this._positionDelta.x = position; 1343 this._positionDelta.y = y; 1344 return true; 1345 } 1346 return false; 1347 }, 1348 1349 /** 1350 * returns a new clone of the action 1351 * @returns {cc.MoveBy} 1352 */ 1353 clone:function () { 1354 var action = new cc.MoveBy(); 1355 this._cloneDecoration(action); 1356 action.initWithDuration(this._duration, this._positionDelta); 1357 return action; 1358 }, 1359 1360 /** 1361 * Start the action with target. 1362 * @param {cc.Node} target 1363 */ 1364 startWithTarget:function (target) { 1365 cc.ActionInterval.prototype.startWithTarget.call(this, target); 1366 var locPosX = target.getPositionX(); 1367 var locPosY = target.getPositionY(); 1368 this._previousPosition.x = locPosX; 1369 this._previousPosition.y = locPosY; 1370 this._startPosition.x = locPosX; 1371 this._startPosition.y = locPosY; 1372 }, 1373 1374 /** 1375 * Called once per frame. Time is the number of seconds of a frame interval. 1376 * @param {Number} dt 1377 */ 1378 update:function (dt) { 1379 dt = this._computeEaseTime(dt); 1380 if (this.target) { 1381 var x = this._positionDelta.x * dt; 1382 var y = this._positionDelta.y * dt; 1383 var locStartPosition = this._startPosition; 1384 if (cc.ENABLE_STACKABLE_ACTIONS) { 1385 var targetX = this.target.getPositionX(); 1386 var targetY = this.target.getPositionY(); 1387 var locPreviousPosition = this._previousPosition; 1388 1389 locStartPosition.x = locStartPosition.x + targetX - locPreviousPosition.x; 1390 locStartPosition.y = locStartPosition.y + targetY - locPreviousPosition.y; 1391 x = x + locStartPosition.x; 1392 y = y + locStartPosition.y; 1393 locPreviousPosition.x = x; 1394 locPreviousPosition.y = y; 1395 this.target.setPosition(x, y); 1396 } else { 1397 this.target.setPosition(locStartPosition.x + x, locStartPosition.y + y); 1398 } 1399 } 1400 }, 1401 1402 /** 1403 * MoveTo reverse is not implemented 1404 * @return {cc.MoveBy} 1405 */ 1406 reverse:function () { 1407 var action = new cc.MoveBy(this._duration, cc.p(-this._positionDelta.x, -this._positionDelta.y)); 1408 this._cloneDecoration(action); 1409 this._reverseEaseList(action); 1410 return action; 1411 } 1412 }); 1413 1414 /** 1415 * Create the action. 1416 * Relative to its coordinate moves a certain distance. 1417 * @function 1418 * @param {Number} duration duration in seconds 1419 * @param {cc.Point|Number} deltaPos 1420 * @param {Number} deltaY 1421 * @return {cc.MoveBy} 1422 * @example 1423 * // example 1424 * var actionTo = cc.moveBy(2, cc.p(windowSize.width - 40, windowSize.height - 40)); 1425 */ 1426 cc.moveBy = function (duration, deltaPos, deltaY) { 1427 return new cc.MoveBy(duration, deltaPos, deltaY); 1428 }; 1429 /** 1430 * Please use cc.moveBy instead. 1431 * Relative to its coordinate moves a certain distance. 1432 * @static 1433 * @deprecated since v3.0 please use cc.moveBy instead. 1434 * @param {Number} duration duration in seconds 1435 * @param {cc.Point|Number} deltaPos 1436 * @param {Number} deltaY 1437 * @return {cc.MoveBy} 1438 */ 1439 cc.MoveBy.create = cc.moveBy; 1440 1441 1442 /** 1443 * Moves a CCNode object to the position x,y. x and y are absolute coordinates by modifying it's position attribute. <br/> 1444 * Several CCMoveTo actions can be concurrently called, and the resulting <br/> 1445 * movement will be the sum of individual movements. 1446 * @class 1447 * @extends cc.MoveBy 1448 * @param {Number} duration duration in seconds 1449 * @param {cc.Point|Number} position 1450 * @param {Number} y 1451 * @example 1452 * var actionBy = new cc.MoveTo(2, cc.p(80, 80)); 1453 */ 1454 cc.MoveTo = cc.MoveBy.extend(/** @lends cc.MoveTo# */{ 1455 _endPosition:null, 1456 1457 /** 1458 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 1459 * @param {Number} duration duration in seconds 1460 * @param {cc.Point|Number} position 1461 * @param {Number} y 1462 */ 1463 ctor:function (duration, position, y) { 1464 cc.MoveBy.prototype.ctor.call(this); 1465 this._endPosition = cc.p(0, 0); 1466 1467 position !== undefined && this.initWithDuration(duration, position, y); 1468 }, 1469 1470 /** 1471 * Initializes the action. 1472 * @param {Number} duration duration in seconds 1473 * @param {cc.Point} position 1474 * @param {Number} y 1475 * @return {Boolean} 1476 */ 1477 initWithDuration:function (duration, position, y) { 1478 if (cc.MoveBy.prototype.initWithDuration.call(this, duration, position, y)) { 1479 if(position.x !== undefined) { 1480 y = position.y; 1481 position = position.x; 1482 } 1483 1484 this._endPosition.x = position; 1485 this._endPosition.y = y; 1486 return true; 1487 } 1488 return false; 1489 }, 1490 1491 /** 1492 * returns a new clone of the action 1493 * @returns {cc.MoveTo} 1494 */ 1495 clone:function () { 1496 var action = new cc.MoveTo(); 1497 this._cloneDecoration(action); 1498 action.initWithDuration(this._duration, this._endPosition); 1499 return action; 1500 }, 1501 1502 /** 1503 * Start the action with target. 1504 * @param {cc.Node} target 1505 */ 1506 startWithTarget:function (target) { 1507 cc.MoveBy.prototype.startWithTarget.call(this, target); 1508 this._positionDelta.x = this._endPosition.x - target.getPositionX(); 1509 this._positionDelta.y = this._endPosition.y - target.getPositionY(); 1510 } 1511 }); 1512 1513 /** 1514 * Create new action. 1515 * Moving to the specified coordinates. 1516 * @function 1517 * @param {Number} duration duration in seconds 1518 * @param {cc.Point} position 1519 * @param {Number} y 1520 * @return {cc.MoveBy} 1521 * @example 1522 * // example 1523 * var actionBy = cc.moveTo(2, cc.p(80, 80)); 1524 */ 1525 cc.moveTo = function (duration, position, y) { 1526 return new cc.MoveTo(duration, position, y); 1527 }; 1528 /** 1529 * Please use cc.moveTo instead. 1530 * Moving to the specified coordinates. 1531 * @static 1532 * @deprecated since v3.0 <br /> Please use cc.moveTo instead. 1533 * @param {Number} duration duration in seconds 1534 * @param {cc.Point} position 1535 * @param {Number} y 1536 * @return {cc.MoveBy} 1537 */ 1538 cc.MoveTo.create = cc.moveTo; 1539 1540 /** 1541 * Skews a cc.Node object to given angles by modifying it's skewX and skewY attributes 1542 * @class 1543 * @extends cc.ActionInterval 1544 * @param {Number} t time in seconds 1545 * @param {Number} sx 1546 * @param {Number} sy 1547 * @example 1548 * var actionTo = new cc.SkewTo(2, 37.2, -37.2); 1549 */ 1550 cc.SkewTo = cc.ActionInterval.extend(/** @lends cc.SkewTo# */{ 1551 _skewX:0, 1552 _skewY:0, 1553 _startSkewX:0, 1554 _startSkewY:0, 1555 _endSkewX:0, 1556 _endSkewY:0, 1557 _deltaX:0, 1558 _deltaY:0, 1559 1560 /** 1561 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 1562 * @param {Number} t time in seconds 1563 * @param {Number} sx 1564 * @param {Number} sy 1565 */ 1566 ctor: function (t, sx, sy) { 1567 cc.ActionInterval.prototype.ctor.call(this); 1568 1569 sy !== undefined && this.initWithDuration(t, sx, sy); 1570 }, 1571 1572 /** 1573 * Initializes the action. 1574 * @param {Number} t time in seconds 1575 * @param {Number} sx 1576 * @param {Number} sy 1577 * @return {Boolean} 1578 */ 1579 initWithDuration:function (t, sx, sy) { 1580 var ret = false; 1581 if (cc.ActionInterval.prototype.initWithDuration.call(this, t)) { 1582 this._endSkewX = sx; 1583 this._endSkewY = sy; 1584 ret = true; 1585 } 1586 return ret; 1587 }, 1588 1589 /** 1590 * returns a new clone of the action 1591 * @returns {cc.SkewTo} 1592 */ 1593 clone:function () { 1594 var action = new cc.SkewTo(); 1595 this._cloneDecoration(action); 1596 action.initWithDuration(this._duration, this._endSkewX, this._endSkewY); 1597 return action; 1598 }, 1599 1600 /** 1601 * Start the action with target. 1602 * @param {cc.Node} target 1603 */ 1604 startWithTarget:function (target) { 1605 cc.ActionInterval.prototype.startWithTarget.call(this, target); 1606 1607 this._startSkewX = target.skewX % 180; 1608 this._deltaX = this._endSkewX - this._startSkewX; 1609 if (this._deltaX > 180) 1610 this._deltaX -= 360; 1611 if (this._deltaX < -180) 1612 this._deltaX += 360; 1613 1614 this._startSkewY = target.skewY % 360; 1615 this._deltaY = this._endSkewY - this._startSkewY; 1616 if (this._deltaY > 180) 1617 this._deltaY -= 360; 1618 if (this._deltaY < -180) 1619 this._deltaY += 360; 1620 }, 1621 1622 /** 1623 * Called once per frame. Time is the number of seconds of a frame interval. 1624 * @param {Number} dt 1625 */ 1626 update:function (dt) { 1627 dt = this._computeEaseTime(dt); 1628 this.target.skewX = this._startSkewX + this._deltaX * dt; 1629 this.target.skewY = this._startSkewY + this._deltaY * dt; 1630 } 1631 }); 1632 /** 1633 * Create new action. 1634 * Skews a cc.Node object to given angles by modifying it's skewX and skewY attributes. 1635 * Changes to the specified value. 1636 * @function 1637 * @param {Number} t time in seconds 1638 * @param {Number} sx 1639 * @param {Number} sy 1640 * @return {cc.SkewTo} 1641 * @example 1642 * // example 1643 * var actionTo = cc.skewTo(2, 37.2, -37.2); 1644 */ 1645 cc.skewTo = function (t, sx, sy) { 1646 return new cc.SkewTo(t, sx, sy); 1647 }; 1648 /** 1649 * Please use cc.skewTo instead. 1650 * Skews a cc.Node object to given angles by modifying it's skewX and skewY attributes。 1651 * Changes to the specified value. 1652 * @static 1653 * @deprecated since v3.0 <br /> Please use cc.skewTo instead. 1654 * @param {Number} t time in seconds 1655 * @param {Number} sx 1656 * @param {Number} sy 1657 * @return {cc.SkewTo} 1658 */ 1659 cc.SkewTo.create = cc.skewTo; 1660 1661 /** 1662 * Skews a cc.Node object by skewX and skewY degrees. 1663 * Relative to its attribute modification. 1664 * @class 1665 * @extends cc.SkewTo 1666 * @param {Number} t time in seconds 1667 * @param {Number} sx skew in degrees for X axis 1668 * @param {Number} sy skew in degrees for Y axis 1669 */ 1670 cc.SkewBy = cc.SkewTo.extend(/** @lends cc.SkewBy# */{ 1671 1672 /** 1673 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 1674 * @param {Number} t time in seconds 1675 * @param {Number} sx skew in degrees for X axis 1676 * @param {Number} sy skew in degrees for Y axis 1677 */ 1678 ctor: function(t, sx, sy) { 1679 cc.SkewTo.prototype.ctor.call(this); 1680 sy !== undefined && this.initWithDuration(t, sx, sy); 1681 }, 1682 1683 /** 1684 * Initializes the action. 1685 * @param {Number} t time in seconds 1686 * @param {Number} deltaSkewX skew in degrees for X axis 1687 * @param {Number} deltaSkewY skew in degrees for Y axis 1688 * @return {Boolean} 1689 */ 1690 initWithDuration:function (t, deltaSkewX, deltaSkewY) { 1691 var ret = false; 1692 if (cc.SkewTo.prototype.initWithDuration.call(this, t, deltaSkewX, deltaSkewY)) { 1693 this._skewX = deltaSkewX; 1694 this._skewY = deltaSkewY; 1695 ret = true; 1696 } 1697 return ret; 1698 }, 1699 1700 /** 1701 * returns a new clone of the action 1702 * @returns {cc.SkewBy} 1703 */ 1704 clone:function () { 1705 var action = new cc.SkewBy(); 1706 this._cloneDecoration(action); 1707 action.initWithDuration(this._duration, this._skewX, this._skewY); 1708 return action; 1709 }, 1710 1711 /** 1712 * Start the action width target. 1713 * @param {cc.Node} target 1714 */ 1715 startWithTarget:function (target) { 1716 cc.SkewTo.prototype.startWithTarget.call(this, target); 1717 this._deltaX = this._skewX; 1718 this._deltaY = this._skewY; 1719 this._endSkewX = this._startSkewX + this._deltaX; 1720 this._endSkewY = this._startSkewY + this._deltaY; 1721 }, 1722 1723 /** 1724 * Returns a reversed action. 1725 * @return {cc.SkewBy} 1726 */ 1727 reverse:function () { 1728 var action = new cc.SkewBy(this._duration, -this._skewX, -this._skewY); 1729 this._cloneDecoration(action); 1730 this._reverseEaseList(action); 1731 return action; 1732 } 1733 }); 1734 1735 /** 1736 * Skews a cc.Node object by skewX and skewY degrees. <br /> 1737 * Relative to its attribute modification. 1738 * @function 1739 * @param {Number} t time in seconds 1740 * @param {Number} sx sx skew in degrees for X axis 1741 * @param {Number} sy sy skew in degrees for Y axis 1742 * @return {cc.SkewBy} 1743 * @example 1744 * // example 1745 * var actionBy = cc.skewBy(2, 0, -90); 1746 */ 1747 cc.skewBy = function (t, sx, sy) { 1748 return new cc.SkewBy(t, sx, sy); 1749 }; 1750 /** 1751 * Please use cc.skewBy instead. <br /> 1752 * Skews a cc.Node object by skewX and skewY degrees. <br /> 1753 * Relative to its attribute modification. 1754 * @static 1755 * @deprecated since v3.0 please use cc.skewBy instead. 1756 * @param {Number} t time in seconds 1757 * @param {Number} sx sx skew in degrees for X axis 1758 * @param {Number} sy sy skew in degrees for Y axis 1759 * @return {cc.SkewBy} 1760 */ 1761 cc.SkewBy.create = cc.skewBy; 1762 1763 1764 /** 1765 * Moves a cc.Node object simulating a parabolic jump movement by modifying it's position attribute. 1766 * Relative to its movement. 1767 * @class 1768 * @extends cc.ActionInterval 1769 * @param {Number} duration 1770 * @param {cc.Point|Number} position 1771 * @param {Number} [y] 1772 * @param {Number} height 1773 * @param {Number} jumps 1774 * @example 1775 * var actionBy = new cc.JumpBy(2, cc.p(300, 0), 50, 4); 1776 * var actionBy = new cc.JumpBy(2, 300, 0, 50, 4); 1777 */ 1778 cc.JumpBy = cc.ActionInterval.extend(/** @lends cc.JumpBy# */{ 1779 _startPosition:null, 1780 _delta:null, 1781 _height:0, 1782 _jumps:0, 1783 _previousPosition:null, 1784 1785 /** 1786 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 1787 * @param {Number} duration 1788 * @param {cc.Point|Number} position 1789 * @param {Number} [y] 1790 * @param {Number} height 1791 * @param {Number} jumps 1792 */ 1793 ctor:function (duration, position, y, height, jumps) { 1794 cc.ActionInterval.prototype.ctor.call(this); 1795 this._startPosition = cc.p(0, 0); 1796 this._previousPosition = cc.p(0, 0); 1797 this._delta = cc.p(0, 0); 1798 1799 height !== undefined && this.initWithDuration(duration, position, y, height, jumps); 1800 }, 1801 /** 1802 * Initializes the action. 1803 * @param {Number} duration 1804 * @param {cc.Point|Number} position 1805 * @param {Number} [y] 1806 * @param {Number} height 1807 * @param {Number} jumps 1808 * @return {Boolean} 1809 * @example 1810 * actionBy.initWithDuration(2, cc.p(300, 0), 50, 4); 1811 * actionBy.initWithDuration(2, 300, 0, 50, 4); 1812 */ 1813 initWithDuration:function (duration, position, y, height, jumps) { 1814 if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) { 1815 if (jumps === undefined) { 1816 jumps = height; 1817 height = y; 1818 y = position.y; 1819 position = position.x; 1820 } 1821 this._delta.x = position; 1822 this._delta.y = y; 1823 this._height = height; 1824 this._jumps = jumps; 1825 return true; 1826 } 1827 return false; 1828 }, 1829 1830 /** 1831 * returns a new clone of the action 1832 * @returns {cc.JumpBy} 1833 */ 1834 clone:function () { 1835 var action = new cc.JumpBy(); 1836 this._cloneDecoration(action); 1837 action.initWithDuration(this._duration, this._delta, this._height, this._jumps); 1838 return action; 1839 }, 1840 1841 /** 1842 * Start the action with target. 1843 * @param {cc.Node} target 1844 */ 1845 startWithTarget:function (target) { 1846 cc.ActionInterval.prototype.startWithTarget.call(this, target); 1847 var locPosX = target.getPositionX(); 1848 var locPosY = target.getPositionY(); 1849 this._previousPosition.x = locPosX; 1850 this._previousPosition.y = locPosY; 1851 this._startPosition.x = locPosX; 1852 this._startPosition.y = locPosY; 1853 }, 1854 1855 /** 1856 * Called once per frame. Time is the number of seconds of a frame interval. 1857 * @param {Number} dt 1858 */ 1859 update:function (dt) { 1860 dt = this._computeEaseTime(dt); 1861 if (this.target) { 1862 var frac = dt * this._jumps % 1.0; 1863 var y = this._height * 4 * frac * (1 - frac); 1864 y += this._delta.y * dt; 1865 1866 var x = this._delta.x * dt; 1867 var locStartPosition = this._startPosition; 1868 if (cc.ENABLE_STACKABLE_ACTIONS) { 1869 var targetX = this.target.getPositionX(); 1870 var targetY = this.target.getPositionY(); 1871 var locPreviousPosition = this._previousPosition; 1872 1873 locStartPosition.x = locStartPosition.x + targetX - locPreviousPosition.x; 1874 locStartPosition.y = locStartPosition.y + targetY - locPreviousPosition.y; 1875 x = x + locStartPosition.x; 1876 y = y + locStartPosition.y; 1877 locPreviousPosition.x = x; 1878 locPreviousPosition.y = y; 1879 this.target.setPosition(x, y); 1880 } else { 1881 this.target.setPosition(locStartPosition.x + x, locStartPosition.y + y); 1882 } 1883 } 1884 }, 1885 1886 /** 1887 * Returns a reversed action. 1888 * @return {cc.JumpBy} 1889 */ 1890 reverse:function () { 1891 var action = new cc.JumpBy(this._duration, cc.p(-this._delta.x, -this._delta.y), this._height, this._jumps); 1892 this._cloneDecoration(action); 1893 this._reverseEaseList(action); 1894 return action; 1895 } 1896 }); 1897 1898 /** 1899 * Moves a cc.Node object simulating a parabolic jump movement by modifying it's position attribute. 1900 * Relative to its movement. 1901 * @function 1902 * @param {Number} duration 1903 * @param {cc.Point|Number} position 1904 * @param {Number} [y] 1905 * @param {Number} height 1906 * @param {Number} jumps 1907 * @return {cc.JumpBy} 1908 * @example 1909 * // example 1910 * var actionBy = cc.jumpBy(2, cc.p(300, 0), 50, 4); 1911 * var actionBy = cc.jumpBy(2, 300, 0, 50, 4); 1912 */ 1913 cc.jumpBy = function (duration, position, y, height, jumps) { 1914 return new cc.JumpBy(duration, position, y, height, jumps); 1915 }; 1916 /** 1917 * Please use cc.jumpBy instead. <br /> 1918 * Moves a cc.Node object simulating a parabolic jump movement by modifying it's position attribute. <br /> 1919 * Relative to its movement. 1920 * @static 1921 * @deprecated since v3.0 please use cc.jumpBy instead. 1922 * @param {Number} duration 1923 * @param {cc.Point|Number} position 1924 * @param {Number} [y] 1925 * @param {Number} height 1926 * @param {Number} jumps 1927 * @return {cc.JumpBy} 1928 */ 1929 cc.JumpBy.create = cc.jumpBy; 1930 1931 /** 1932 * Moves a cc.Node object to a parabolic position simulating a jump movement by modifying it's position attribute. <br /> 1933 * Jump to the specified location. 1934 * @class 1935 * @extends cc.JumpBy 1936 * @param {Number} duration 1937 * @param {cc.Point|Number} position 1938 * @param {Number} [y] 1939 * @param {Number} height 1940 * @param {Number} jumps 1941 * @example 1942 * var actionTo = new cc.JumpTo(2, cc.p(300, 0), 50, 4); 1943 * var actionTo = new cc.JumpTo(2, 300, 0, 50, 4); 1944 */ 1945 cc.JumpTo = cc.JumpBy.extend(/** @lends cc.JumpTo# */{ 1946 _endPosition:null, 1947 1948 /** 1949 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 1950 * @param {Number} duration 1951 * @param {cc.Point|Number} position 1952 * @param {Number} [y] 1953 * @param {Number} height 1954 * @param {Number} jumps 1955 */ 1956 ctor:function (duration, position, y, height, jumps) { 1957 cc.JumpBy.prototype.ctor.call(this); 1958 this._endPosition = cc.p(0, 0); 1959 1960 height !== undefined && this.initWithDuration(duration, position, y, height, jumps); 1961 }, 1962 /** 1963 * Initializes the action. 1964 * @param {Number} duration 1965 * @param {cc.Point|Number} position 1966 * @param {Number} [y] 1967 * @param {Number} height 1968 * @param {Number} jumps 1969 * @return {Boolean} 1970 * @example 1971 * actionTo.initWithDuration(2, cc.p(300, 0), 50, 4); 1972 * actionTo.initWithDuration(2, 300, 0, 50, 4); 1973 */ 1974 initWithDuration:function (duration, position, y, height, jumps) { 1975 if (cc.JumpBy.prototype.initWithDuration.call(this, duration, position, y, height, jumps)) { 1976 if (jumps === undefined) { 1977 y = position.y; 1978 position = position.x; 1979 } 1980 this._endPosition.x = position; 1981 this._endPosition.y = y; 1982 return true; 1983 } 1984 return false; 1985 }, 1986 /** 1987 * Start the action with target. 1988 * @param {cc.Node} target 1989 */ 1990 startWithTarget:function (target) { 1991 cc.JumpBy.prototype.startWithTarget.call(this, target); 1992 this._delta.x = this._endPosition.x - this._startPosition.x; 1993 this._delta.y = this._endPosition.y - this._startPosition.y; 1994 }, 1995 1996 /** 1997 * returns a new clone of the action 1998 * @returns {cc.JumpTo} 1999 */ 2000 clone:function () { 2001 var action = new cc.JumpTo(); 2002 this._cloneDecoration(action); 2003 action.initWithDuration(this._duration, this._endPosition, this._height, this._jumps); 2004 return action; 2005 } 2006 }); 2007 2008 /** 2009 * Moves a cc.Node object to a parabolic position simulating a jump movement by modifying it's position attribute. <br /> 2010 * Jump to the specified location. 2011 * @function 2012 * @param {Number} duration 2013 * @param {cc.Point|Number} position 2014 * @param {Number} [y] 2015 * @param {Number} height 2016 * @param {Number} jumps 2017 * @return {cc.JumpTo} 2018 * @example 2019 * // example 2020 * var actionTo = cc.jumpTo(2, cc.p(300, 300), 50, 4); 2021 * var actionTo = cc.jumpTo(2, 300, 300, 50, 4); 2022 */ 2023 cc.jumpTo = function (duration, position, y, height, jumps) { 2024 return new cc.JumpTo(duration, position, y, height, jumps); 2025 }; 2026 /** 2027 * Please use cc.jumpTo instead. 2028 * Moves a cc.Node object to a parabolic position simulating a jump movement by modifying it's position attribute. <br /> 2029 * Jump to the specified location. 2030 * @static 2031 * @deprecated since v3.0 please use cc.jumpTo instead. 2032 * @param {Number} duration 2033 * @param {cc.Point|Number} position 2034 * @param {Number} [y] 2035 * @param {Number} height 2036 * @param {Number} jumps 2037 * @return {cc.JumpTo} 2038 */ 2039 cc.JumpTo.create = cc.jumpTo; 2040 2041 /** 2042 * @function 2043 * @param {Number} a 2044 * @param {Number} b 2045 * @param {Number} c 2046 * @param {Number} d 2047 * @param {Number} t 2048 * @return {Number} 2049 */ 2050 cc.bezierAt = function (a, b, c, d, t) { 2051 return (Math.pow(1 - t, 3) * a + 2052 3 * t * (Math.pow(1 - t, 2)) * b + 2053 3 * Math.pow(t, 2) * (1 - t) * c + 2054 Math.pow(t, 3) * d ); 2055 }; 2056 2057 /** An action that moves the target with a cubic Bezier curve by a certain distance. 2058 * Relative to its movement. 2059 * @class 2060 * @extends cc.ActionInterval 2061 * @param {Number} t time in seconds 2062 * @param {Array} c Array of points 2063 * @example 2064 * var bezier = [cc.p(0, windowSize.height / 2), cc.p(300, -windowSize.height / 2), cc.p(300, 100)]; 2065 * var bezierForward = new cc.BezierBy(3, bezier); 2066 */ 2067 cc.BezierBy = cc.ActionInterval.extend(/** @lends cc.BezierBy# */{ 2068 _config:null, 2069 _startPosition:null, 2070 _previousPosition:null, 2071 2072 /** 2073 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 2074 * @param {Number} t time in seconds 2075 * @param {Array} c Array of points 2076 */ 2077 ctor:function (t, c) { 2078 cc.ActionInterval.prototype.ctor.call(this); 2079 this._config = []; 2080 this._startPosition = cc.p(0, 0); 2081 this._previousPosition = cc.p(0, 0); 2082 2083 c && this.initWithDuration(t, c); 2084 }, 2085 2086 /** 2087 * Initializes the action. 2088 * @param {Number} t time in seconds 2089 * @param {Array} c Array of points 2090 * @return {Boolean} 2091 */ 2092 initWithDuration:function (t, c) { 2093 if (cc.ActionInterval.prototype.initWithDuration.call(this, t)) { 2094 this._config = c; 2095 return true; 2096 } 2097 return false; 2098 }, 2099 2100 /** 2101 * returns a new clone of the action 2102 * @returns {cc.BezierBy} 2103 */ 2104 clone:function () { 2105 var action = new cc.BezierBy(); 2106 this._cloneDecoration(action); 2107 var newConfigs = []; 2108 for (var i = 0; i < this._config.length; i++) { 2109 var selConf = this._config[i]; 2110 newConfigs.push(cc.p(selConf.x, selConf.y)); 2111 } 2112 action.initWithDuration(this._duration, newConfigs); 2113 return action; 2114 }, 2115 2116 /** 2117 * Start the action with target. 2118 * @param {cc.Node} target 2119 */ 2120 startWithTarget:function (target) { 2121 cc.ActionInterval.prototype.startWithTarget.call(this, target); 2122 var locPosX = target.getPositionX(); 2123 var locPosY = target.getPositionY(); 2124 this._previousPosition.x = locPosX; 2125 this._previousPosition.y = locPosY; 2126 this._startPosition.x = locPosX; 2127 this._startPosition.y = locPosY; 2128 }, 2129 2130 /** 2131 * Called once per frame. Time is the number of seconds of a frame interval. 2132 * @param {Number} dt 2133 */ 2134 update:function (dt) { 2135 dt = this._computeEaseTime(dt); 2136 if (this.target) { 2137 var locConfig = this._config; 2138 var xa = 0; 2139 var xb = locConfig[0].x; 2140 var xc = locConfig[1].x; 2141 var xd = locConfig[2].x; 2142 2143 var ya = 0; 2144 var yb = locConfig[0].y; 2145 var yc = locConfig[1].y; 2146 var yd = locConfig[2].y; 2147 2148 var x = cc.bezierAt(xa, xb, xc, xd, dt); 2149 var y = cc.bezierAt(ya, yb, yc, yd, dt); 2150 2151 var locStartPosition = this._startPosition; 2152 if (cc.ENABLE_STACKABLE_ACTIONS) { 2153 var targetX = this.target.getPositionX(); 2154 var targetY = this.target.getPositionY(); 2155 var locPreviousPosition = this._previousPosition; 2156 2157 locStartPosition.x = locStartPosition.x + targetX - locPreviousPosition.x; 2158 locStartPosition.y = locStartPosition.y + targetY - locPreviousPosition.y; 2159 x = x + locStartPosition.x; 2160 y = y + locStartPosition.y; 2161 locPreviousPosition.x = x; 2162 locPreviousPosition.y = y; 2163 this.target.setPosition(x, y); 2164 } else { 2165 this.target.setPosition(locStartPosition.x + x, locStartPosition.y + y); 2166 } 2167 } 2168 }, 2169 2170 /** 2171 * Returns a reversed action. 2172 * @return {cc.BezierBy} 2173 */ 2174 reverse:function () { 2175 var locConfig = this._config; 2176 var r = [ 2177 cc.pAdd(locConfig[1], cc.pNeg(locConfig[2])), 2178 cc.pAdd(locConfig[0], cc.pNeg(locConfig[2])), 2179 cc.pNeg(locConfig[2]) ]; 2180 var action = new cc.BezierBy(this._duration, r); 2181 this._cloneDecoration(action); 2182 this._reverseEaseList(action); 2183 return action; 2184 } 2185 }); 2186 2187 /** 2188 * An action that moves the target with a cubic Bezier curve by a certain distance. 2189 * Relative to its movement. 2190 * @function 2191 * @param {Number} t time in seconds 2192 * @param {Array} c Array of points 2193 * @return {cc.BezierBy} 2194 * @example 2195 * // example 2196 * var bezier = [cc.p(0, windowSize.height / 2), cc.p(300, -windowSize.height / 2), cc.p(300, 100)]; 2197 * var bezierForward = cc.bezierBy(3, bezier); 2198 */ 2199 cc.bezierBy = function (t, c) { 2200 return new cc.BezierBy(t, c); 2201 }; 2202 /** 2203 * Please use cc.bezierBy instead. 2204 * An action that moves the target with a cubic Bezier curve by a certain distance. 2205 * Relative to its movement. 2206 * @static 2207 * @deprecated since v3.0 please use cc.bezierBy instead. 2208 * @param {Number} t time in seconds 2209 * @param {Array} c Array of points 2210 * @return {cc.BezierBy} 2211 */ 2212 cc.BezierBy.create = cc.bezierBy; 2213 2214 2215 /** An action that moves the target with a cubic Bezier curve to a destination point. 2216 * @class 2217 * @extends cc.BezierBy 2218 * @param {Number} t 2219 * @param {Array} c array of points 2220 * @example 2221 * var bezier = [cc.p(0, windowSize.height / 2), cc.p(300, -windowSize.height / 2), cc.p(300, 100)]; 2222 * var bezierTo = new cc.BezierTo(2, bezier); 2223 */ 2224 cc.BezierTo = cc.BezierBy.extend(/** @lends cc.BezierTo# */{ 2225 _toConfig:null, 2226 2227 /** 2228 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 2229 * @param {Number} t 2230 * @param {Array} c array of points 2231 * var bezierTo = new cc.BezierTo(2, bezier); 2232 */ 2233 ctor:function (t, c) { 2234 cc.BezierBy.prototype.ctor.call(this); 2235 this._toConfig = []; 2236 c && this.initWithDuration(t, c); 2237 }, 2238 2239 /** 2240 * Initializes the action. 2241 * @param {Number} t time in seconds 2242 * @param {Array} c Array of points 2243 * @return {Boolean} 2244 */ 2245 initWithDuration:function (t, c) { 2246 if (cc.ActionInterval.prototype.initWithDuration.call(this, t)) { 2247 this._toConfig = c; 2248 return true; 2249 } 2250 return false; 2251 }, 2252 2253 /** 2254 * returns a new clone of the action 2255 * @returns {cc.BezierTo} 2256 */ 2257 clone:function () { 2258 var action = new cc.BezierTo(); 2259 this._cloneDecoration(action); 2260 action.initWithDuration(this._duration, this._toConfig); 2261 return action; 2262 }, 2263 2264 /** 2265 * Start the action with target. 2266 * @param {cc.Node} target 2267 */ 2268 startWithTarget:function (target) { 2269 cc.BezierBy.prototype.startWithTarget.call(this, target); 2270 var locStartPos = this._startPosition; 2271 var locToConfig = this._toConfig; 2272 var locConfig = this._config; 2273 2274 locConfig[0] = cc.pSub(locToConfig[0], locStartPos); 2275 locConfig[1] = cc.pSub(locToConfig[1], locStartPos); 2276 locConfig[2] = cc.pSub(locToConfig[2], locStartPos); 2277 } 2278 }); 2279 /** 2280 * An action that moves the target with a cubic Bezier curve to a destination point. 2281 * @function 2282 * @param {Number} t 2283 * @param {Array} c array of points 2284 * @return {cc.BezierTo} 2285 * @example 2286 * // example 2287 * var bezier = [cc.p(0, windowSize.height / 2), cc.p(300, -windowSize.height / 2), cc.p(300, 100)]; 2288 * var bezierTo = cc.bezierTo(2, bezier); 2289 */ 2290 cc.bezierTo = function (t, c) { 2291 return new cc.BezierTo(t, c); 2292 }; 2293 /** 2294 * Please use cc.bezierTo instead 2295 * @static 2296 * @deprecated since v3.0 please use cc.bezierTo instead. 2297 * @param {Number} t 2298 * @param {Array} c array of points 2299 * @return {cc.BezierTo} 2300 */ 2301 cc.BezierTo.create = cc.bezierTo; 2302 2303 2304 /** Scales a cc.Node object to a zoom factor by modifying it's scale attribute. 2305 * @warning This action doesn't support "reverse" 2306 * @class 2307 * @extends cc.ActionInterval 2308 * @param {Number} duration 2309 * @param {Number} sx scale parameter in X 2310 * @param {Number} [sy] scale parameter in Y, if Null equal to sx 2311 * @example 2312 * // It scales to 0.5 in both X and Y. 2313 * var actionTo = new cc.ScaleTo(2, 0.5); 2314 * 2315 * // It scales to 0.5 in x and 2 in Y 2316 * var actionTo = new cc.ScaleTo(2, 0.5, 2); 2317 */ 2318 cc.ScaleTo = cc.ActionInterval.extend(/** @lends cc.ScaleTo# */{ 2319 _scaleX:1, 2320 _scaleY:1, 2321 _startScaleX:1, 2322 _startScaleY:1, 2323 _endScaleX:0, 2324 _endScaleY:0, 2325 _deltaX:0, 2326 _deltaY:0, 2327 2328 /** 2329 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 2330 * @param {Number} duration 2331 * @param {Number} sx scale parameter in X 2332 * @param {Number} [sy] scale parameter in Y, if Null equal to sx 2333 */ 2334 ctor:function (duration, sx, sy) { 2335 cc.ActionInterval.prototype.ctor.call(this); 2336 sx !== undefined && this.initWithDuration(duration, sx, sy); 2337 }, 2338 2339 /** 2340 * Initializes the action. 2341 * @param {Number} duration 2342 * @param {Number} sx 2343 * @param {Number} [sy=] 2344 * @return {Boolean} 2345 */ 2346 initWithDuration:function (duration, sx, sy) { //function overload here 2347 if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) { 2348 this._endScaleX = sx; 2349 this._endScaleY = (sy != null) ? sy : sx; 2350 return true; 2351 } 2352 return false; 2353 }, 2354 2355 /** 2356 * returns a new clone of the action 2357 * @returns {cc.ScaleTo} 2358 */ 2359 clone:function () { 2360 var action = new cc.ScaleTo(); 2361 this._cloneDecoration(action); 2362 action.initWithDuration(this._duration, this._endScaleX, this._endScaleY); 2363 return action; 2364 }, 2365 2366 /** 2367 * Start the action with target. 2368 * @param {cc.Node} target 2369 */ 2370 startWithTarget:function (target) { 2371 cc.ActionInterval.prototype.startWithTarget.call(this, target); 2372 this._startScaleX = target.scaleX; 2373 this._startScaleY = target.scaleY; 2374 this._deltaX = this._endScaleX - this._startScaleX; 2375 this._deltaY = this._endScaleY - this._startScaleY; 2376 }, 2377 2378 /** 2379 * Called once per frame. Time is the number of seconds of a frame interval. 2380 * @param {Number} dt 2381 */ 2382 update:function (dt) { 2383 dt = this._computeEaseTime(dt); 2384 if (this.target) { 2385 this.target.scaleX = this._startScaleX + this._deltaX * dt; 2386 this.target.scaleY = this._startScaleY + this._deltaY * dt; 2387 } 2388 } 2389 }); 2390 /** 2391 * Scales a cc.Node object to a zoom factor by modifying it's scale attribute. 2392 * @function 2393 * @param {Number} duration 2394 * @param {Number} sx scale parameter in X 2395 * @param {Number} [sy] scale parameter in Y, if Null equal to sx 2396 * @return {cc.ScaleTo} 2397 * @example 2398 * // example 2399 * // It scales to 0.5 in both X and Y. 2400 * var actionTo = cc.scaleTo(2, 0.5); 2401 * 2402 * // It scales to 0.5 in x and 2 in Y 2403 * var actionTo = cc.scaleTo(2, 0.5, 2); 2404 */ 2405 cc.scaleTo = function (duration, sx, sy) { //function overload 2406 return new cc.ScaleTo(duration, sx, sy); 2407 }; 2408 /** 2409 * Please use cc.scaleTo instead. 2410 * Scales a cc.Node object to a zoom factor by modifying it's scale attribute. 2411 * @static 2412 * @deprecated since v3.0 please use cc.scaleTo instead. 2413 * @param {Number} duration 2414 * @param {Number} sx scale parameter in X 2415 * @param {Number} [sy] scale parameter in Y, if Null equal to sx 2416 * @return {cc.ScaleTo} 2417 */ 2418 cc.ScaleTo.create = cc.scaleTo; 2419 2420 2421 /** Scales a cc.Node object a zoom factor by modifying it's scale attribute. 2422 * Relative to its changes. 2423 * @class 2424 * @extends cc.ScaleTo 2425 */ 2426 cc.ScaleBy = cc.ScaleTo.extend(/** @lends cc.ScaleBy# */{ 2427 /** 2428 * Start the action with target. 2429 * @param {cc.Node} target 2430 */ 2431 startWithTarget:function (target) { 2432 cc.ScaleTo.prototype.startWithTarget.call(this, target); 2433 this._deltaX = this._startScaleX * this._endScaleX - this._startScaleX; 2434 this._deltaY = this._startScaleY * this._endScaleY - this._startScaleY; 2435 }, 2436 2437 /** 2438 * Returns a reversed action. 2439 * @return {cc.ScaleBy} 2440 */ 2441 reverse:function () { 2442 var action = new cc.ScaleBy(this._duration, 1 / this._endScaleX, 1 / this._endScaleY); 2443 this._cloneDecoration(action); 2444 this._reverseEaseList(action); 2445 return action; 2446 }, 2447 2448 /** 2449 * returns a new clone of the action 2450 * @returns {cc.ScaleBy} 2451 */ 2452 clone:function () { 2453 var action = new cc.ScaleBy(); 2454 this._cloneDecoration(action); 2455 action.initWithDuration(this._duration, this._endScaleX, this._endScaleY); 2456 return action; 2457 } 2458 }); 2459 /** 2460 * Scales a cc.Node object a zoom factor by modifying it's scale attribute. 2461 * Relative to its changes. 2462 * @function 2463 * @param {Number} duration duration in seconds 2464 * @param {Number} sx sx scale parameter in X 2465 * @param {Number|Null} [sy=] sy scale parameter in Y, if Null equal to sx 2466 * @return {cc.ScaleBy} 2467 * @example 2468 * // example without sy, it scales by 2 both in X and Y 2469 * var actionBy = cc.scaleBy(2, 2); 2470 * 2471 * //example with sy, it scales by 0.25 in X and 4.5 in Y 2472 * var actionBy2 = cc.scaleBy(2, 0.25, 4.5); 2473 */ 2474 cc.scaleBy = function (duration, sx, sy) { 2475 return new cc.ScaleBy(duration, sx, sy); 2476 }; 2477 /** 2478 * Please use cc.scaleBy instead. 2479 * Scales a cc.Node object a zoom factor by modifying it's scale attribute. 2480 * Relative to its changes. 2481 * @static 2482 * @deprecated since v3.0 please use cc.scaleBy() instead. 2483 * @param {Number} duration duration in seconds 2484 * @param {Number} sx sx scale parameter in X 2485 * @param {Number|Null} [sy=] sy scale parameter in Y, if Null equal to sx 2486 * @return {cc.ScaleBy} 2487 */ 2488 cc.ScaleBy.create = cc.scaleBy; 2489 2490 /** Blinks a cc.Node object by modifying it's visible attribute 2491 * @class 2492 * @extends cc.ActionInterval 2493 * @param {Number} duration duration in seconds 2494 * @param {Number} blinks blinks in times 2495 * @example 2496 * var action = new cc.Blink(2, 10); 2497 */ 2498 cc.Blink = cc.ActionInterval.extend(/** @lends cc.Blink# */{ 2499 _times:0, 2500 _originalState:false, 2501 2502 /** 2503 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 2504 * @param {Number} duration duration in seconds 2505 * @param {Number} blinks blinks in times 2506 */ 2507 ctor:function (duration, blinks) { 2508 cc.ActionInterval.prototype.ctor.call(this); 2509 blinks !== undefined && this.initWithDuration(duration, blinks); 2510 }, 2511 2512 /** 2513 * Initializes the action. 2514 * @param {Number} duration duration in seconds 2515 * @param {Number} blinks blinks in times 2516 * @return {Boolean} 2517 */ 2518 initWithDuration:function (duration, blinks) { 2519 if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) { 2520 this._times = blinks; 2521 return true; 2522 } 2523 return false; 2524 }, 2525 2526 /** 2527 * returns a new clone of the action 2528 * @returns {cc.Blink} 2529 */ 2530 clone:function () { 2531 var action = new cc.Blink(); 2532 this._cloneDecoration(action); 2533 action.initWithDuration(this._duration, this._times); 2534 return action; 2535 }, 2536 2537 /** 2538 * Called once per frame. Time is the number of seconds of a frame interval. 2539 * @param {Number} dt time in seconds 2540 */ 2541 update:function (dt) { 2542 dt = this._computeEaseTime(dt); 2543 if (this.target && !this.isDone()) { 2544 var slice = 1.0 / this._times; 2545 var m = dt % slice; 2546 this.target.visible = (m > (slice / 2)); 2547 } 2548 }, 2549 2550 /** 2551 * Start the action with target. 2552 * @param {cc.Node} target 2553 */ 2554 startWithTarget:function (target) { 2555 cc.ActionInterval.prototype.startWithTarget.call(this, target); 2556 this._originalState = target.visible; 2557 }, 2558 2559 /** 2560 * stop the action 2561 */ 2562 stop:function () { 2563 this.target.visible = this._originalState; 2564 cc.ActionInterval.prototype.stop.call(this); 2565 }, 2566 2567 /** 2568 * Returns a reversed action. 2569 * @return {cc.Blink} 2570 */ 2571 reverse:function () { 2572 var action = new cc.Blink(this._duration, this._times); 2573 this._cloneDecoration(action); 2574 this._reverseEaseList(action); 2575 return action; 2576 } 2577 }); 2578 /** 2579 * Blinks a cc.Node object by modifying it's visible attribute. 2580 * @function 2581 * @param {Number} duration duration in seconds 2582 * @param blinks blinks in times 2583 * @return {cc.Blink} 2584 * @example 2585 * // example 2586 * var action = cc.blink(2, 10); 2587 */ 2588 cc.blink = function (duration, blinks) { 2589 return new cc.Blink(duration, blinks); 2590 }; 2591 /** 2592 * Please use cc.blink instead. 2593 * Blinks a cc.Node object by modifying it's visible attribute. 2594 * @static 2595 * @deprecated since v3.0 please use cc.blink instead. 2596 * @param {Number} duration duration in seconds 2597 * @param blinks blinks in times 2598 * @return {cc.Blink} 2599 */ 2600 cc.Blink.create = cc.blink; 2601 2602 /** Fades an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from the current value to a custom one. 2603 * @warning This action doesn't support "reverse" 2604 * @class 2605 * @extends cc.ActionInterval 2606 * @param {Number} duration 2607 * @param {Number} opacity 0-255, 0 is transparent 2608 * @example 2609 * var action = new cc.FadeTo(1.0, 0); 2610 */ 2611 cc.FadeTo = cc.ActionInterval.extend(/** @lends cc.FadeTo# */{ 2612 _toOpacity:0, 2613 _fromOpacity:0, 2614 2615 /** 2616 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 2617 * @param {Number} duration 2618 * @param {Number} opacity 0-255, 0 is transparent 2619 */ 2620 ctor:function (duration, opacity) { 2621 cc.ActionInterval.prototype.ctor.call(this); 2622 opacity !== undefined && this.initWithDuration(duration, opacity); 2623 }, 2624 2625 /** 2626 * Initializes the action. 2627 * @param {Number} duration duration in seconds 2628 * @param {Number} opacity 2629 * @return {Boolean} 2630 */ 2631 initWithDuration:function (duration, opacity) { 2632 if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) { 2633 this._toOpacity = opacity; 2634 return true; 2635 } 2636 return false; 2637 }, 2638 2639 /** 2640 * returns a new clone of the action 2641 * @returns {cc.FadeTo} 2642 */ 2643 clone:function () { 2644 var action = new cc.FadeTo(); 2645 this._cloneDecoration(action); 2646 action.initWithDuration(this._duration, this._toOpacity); 2647 return action; 2648 }, 2649 2650 /** 2651 * Called once per frame. Time is the number of seconds of a frame interval. 2652 * @param {Number} time time in seconds 2653 */ 2654 update:function (time) { 2655 time = this._computeEaseTime(time); 2656 var fromOpacity = this._fromOpacity !== undefined ? this._fromOpacity : 255; 2657 this.target.opacity = fromOpacity + (this._toOpacity - fromOpacity) * time; 2658 }, 2659 2660 /** 2661 * Start this action with target. 2662 * @param {cc.Node} target 2663 */ 2664 startWithTarget:function (target) { 2665 cc.ActionInterval.prototype.startWithTarget.call(this, target); 2666 this._fromOpacity = target.opacity; 2667 } 2668 }); 2669 2670 /** 2671 * Fades an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from the current value to a custom one. 2672 * @function 2673 * @param {Number} duration 2674 * @param {Number} opacity 0-255, 0 is transparent 2675 * @return {cc.FadeTo} 2676 * @example 2677 * // example 2678 * var action = cc.fadeTo(1.0, 0); 2679 */ 2680 cc.fadeTo = function (duration, opacity) { 2681 return new cc.FadeTo(duration, opacity); 2682 }; 2683 /** 2684 * Please use cc.fadeTo instead. 2685 * Fades an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from the current value to a custom one. 2686 * @static 2687 * @deprecated since v3.0 please use cc.fadeTo instead. 2688 * @param {Number} duration 2689 * @param {Number} opacity 0-255, 0 is transparent 2690 * @return {cc.FadeTo} 2691 */ 2692 cc.FadeTo.create = cc.fadeTo; 2693 2694 /** Fades In an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from 0 to 255.<br/> 2695 * The "reverse" of this action is FadeOut 2696 * @class 2697 * @extends cc.FadeTo 2698 * @param {Number} duration duration in seconds 2699 */ 2700 cc.FadeIn = cc.FadeTo.extend(/** @lends cc.FadeIn# */{ 2701 _reverseAction: null, 2702 2703 /** 2704 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 2705 * @param {Number} duration duration in seconds 2706 */ 2707 ctor:function (duration) { 2708 cc.FadeTo.prototype.ctor.call(this); 2709 if (duration == null) 2710 duration = 0; 2711 this.initWithDuration(duration, 255); 2712 }, 2713 2714 /** 2715 * Returns a reversed action. 2716 * @return {cc.FadeOut} 2717 */ 2718 reverse:function () { 2719 var action = new cc.FadeOut(); 2720 action.initWithDuration(this._duration, 0); 2721 this._cloneDecoration(action); 2722 this._reverseEaseList(action); 2723 return action; 2724 }, 2725 2726 /** 2727 * returns a new clone of the action 2728 * @returns {cc.FadeIn} 2729 */ 2730 clone:function () { 2731 var action = new cc.FadeIn(); 2732 this._cloneDecoration(action); 2733 action.initWithDuration(this._duration, this._toOpacity); 2734 return action; 2735 }, 2736 2737 /** 2738 * Start the action with target. 2739 * @param {cc.Node} target 2740 */ 2741 startWithTarget:function (target) { 2742 if(this._reverseAction) 2743 this._toOpacity = this._reverseAction._fromOpacity; 2744 cc.FadeTo.prototype.startWithTarget.call(this, target); 2745 } 2746 }); 2747 2748 /** 2749 * Fades In an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from 0 to 255. 2750 * @function 2751 * @param {Number} duration duration in seconds 2752 * @return {cc.FadeIn} 2753 * @example 2754 * //example 2755 * var action = cc.fadeIn(1.0); 2756 */ 2757 cc.fadeIn = function (duration) { 2758 return new cc.FadeIn(duration); 2759 }; 2760 /** 2761 * Please use cc.fadeIn instead. 2762 * Fades In an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from 0 to 255. 2763 * @static 2764 * @deprecated since v3.0 please use cc.fadeIn() instead. 2765 * @param {Number} duration duration in seconds 2766 * @return {cc.FadeIn} 2767 */ 2768 cc.FadeIn.create = cc.fadeIn; 2769 2770 2771 /** Fades Out an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from 255 to 0. 2772 * The "reverse" of this action is FadeIn 2773 * @class 2774 * @extends cc.FadeTo 2775 * @param {Number} duration duration in seconds 2776 */ 2777 cc.FadeOut = cc.FadeTo.extend(/** @lends cc.FadeOut# */{ 2778 2779 /** 2780 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 2781 * @param {Number} duration duration in seconds 2782 */ 2783 ctor:function (duration) { 2784 cc.FadeTo.prototype.ctor.call(this); 2785 if (duration == null) 2786 duration = 0; 2787 this.initWithDuration(duration, 0); 2788 }, 2789 2790 /** 2791 * Returns a reversed action. 2792 * @return {cc.FadeIn} 2793 */ 2794 reverse:function () { 2795 var action = new cc.FadeIn(); 2796 action._reverseAction = this; 2797 action.initWithDuration(this._duration, 255); 2798 this._cloneDecoration(action); 2799 this._reverseEaseList(action); 2800 return action; 2801 }, 2802 2803 /** 2804 * returns a new clone of the action 2805 * @returns {cc.FadeOut} 2806 */ 2807 clone:function () { 2808 var action = new cc.FadeOut(); 2809 this._cloneDecoration(action); 2810 action.initWithDuration(this._duration, this._toOpacity); 2811 return action; 2812 } 2813 }); 2814 2815 /** 2816 * Fades Out an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from 255 to 0. 2817 * @function 2818 * @param {Number} d duration in seconds 2819 * @return {cc.FadeOut} 2820 * @example 2821 * // example 2822 * var action = cc.fadeOut(1.0); 2823 */ 2824 cc.fadeOut = function (d) { 2825 return new cc.FadeOut(d); 2826 }; 2827 /** 2828 * Please use cc.fadeOut instead. 2829 * Fades Out an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from 255 to 0. 2830 * @static 2831 * @deprecated since v3.0 please use cc.fadeOut instead. 2832 * @param {Number} d duration in seconds 2833 * @return {cc.FadeOut} 2834 */ 2835 cc.FadeOut.create = cc.fadeOut; 2836 2837 /** Tints a cc.Node that implements the cc.NodeRGB protocol from current tint to a custom one. 2838 * @warning This action doesn't support "reverse" 2839 * @class 2840 * @extends cc.ActionInterval 2841 * @param {Number} duration 2842 * @param {Number} red 0-255 2843 * @param {Number} green 0-255 2844 * @param {Number} blue 0-255 2845 * @example 2846 * var action = new cc.TintTo(2, 255, 0, 255); 2847 */ 2848 cc.TintTo = cc.ActionInterval.extend(/** @lends cc.TintTo# */{ 2849 _to:null, 2850 _from:null, 2851 2852 /** 2853 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 2854 * @param {Number} duration 2855 * @param {Number} red 0-255 2856 * @param {Number} green 0-255 2857 * @param {Number} blue 0-255 2858 */ 2859 ctor:function (duration, red, green, blue) { 2860 cc.ActionInterval.prototype.ctor.call(this); 2861 this._to = cc.color(0, 0, 0); 2862 this._from = cc.color(0, 0, 0); 2863 2864 blue !== undefined && this.initWithDuration(duration, red, green, blue); 2865 }, 2866 2867 /** 2868 * Initializes the action. 2869 * @param {Number} duration 2870 * @param {Number} red 0-255 2871 * @param {Number} green 0-255 2872 * @param {Number} blue 0-255 2873 * @return {Boolean} 2874 */ 2875 initWithDuration:function (duration, red, green, blue) { 2876 if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) { 2877 this._to = cc.color(red, green, blue); 2878 return true; 2879 } 2880 return false; 2881 }, 2882 2883 /** 2884 * returns a new clone of the action 2885 * @returns {cc.TintTo} 2886 */ 2887 clone:function () { 2888 var action = new cc.TintTo(); 2889 this._cloneDecoration(action); 2890 var locTo = this._to; 2891 action.initWithDuration(this._duration, locTo.r, locTo.g, locTo.b); 2892 return action; 2893 }, 2894 2895 /** 2896 * Start the action with target. 2897 * @param {cc.Node} target 2898 */ 2899 startWithTarget:function (target) { 2900 cc.ActionInterval.prototype.startWithTarget.call(this, target); 2901 2902 this._from = this.target.color; 2903 }, 2904 2905 /** 2906 * Called once per frame. Time is the number of seconds of a frame interval. 2907 * @param {Number} dt time in seconds 2908 */ 2909 update:function (dt) { 2910 dt = this._computeEaseTime(dt); 2911 var locFrom = this._from, locTo = this._to; 2912 if (locFrom) { 2913 this.target.setColor( 2914 cc.color( 2915 locFrom.r + (locTo.r - locFrom.r) * dt, 2916 locFrom.g + (locTo.g - locFrom.g) * dt, 2917 locFrom.b + (locTo.b - locFrom.b) * dt) 2918 ); 2919 } 2920 } 2921 }); 2922 2923 /** 2924 * Tints a cc.Node that implements the cc.NodeRGB protocol from current tint to a custom one. 2925 * @function 2926 * @param {Number} duration 2927 * @param {Number} red 0-255 2928 * @param {Number} green 0-255 2929 * @param {Number} blue 0-255 2930 * @return {cc.TintTo} 2931 * @example 2932 * // example 2933 * var action = cc.tintTo(2, 255, 0, 255); 2934 */ 2935 cc.tintTo = function (duration, red, green, blue) { 2936 return new cc.TintTo(duration, red, green, blue); 2937 }; 2938 /** 2939 * Please use cc.tintTo instead. 2940 * Tints a cc.Node that implements the cc.NodeRGB protocol from current tint to a custom one. 2941 * @static 2942 * @deprecated since v3.0 please use cc.tintTo instead. 2943 * @param {Number} duration 2944 * @param {Number} red 0-255 2945 * @param {Number} green 0-255 2946 * @param {Number} blue 0-255 2947 * @return {cc.TintTo} 2948 */ 2949 cc.TintTo.create = cc.tintTo; 2950 2951 2952 /** Tints a cc.Node that implements the cc.NodeRGB protocol from current tint to a custom one. 2953 * Relative to their own color change. 2954 * @class 2955 * @extends cc.ActionInterval 2956 * @param {Number} duration duration in seconds 2957 * @param {Number} deltaRed 2958 * @param {Number} deltaGreen 2959 * @param {Number} deltaBlue 2960 * @example 2961 * var action = new cc.TintBy(2, -127, -255, -127); 2962 */ 2963 cc.TintBy = cc.ActionInterval.extend(/** @lends cc.TintBy# */{ 2964 _deltaR:0, 2965 _deltaG:0, 2966 _deltaB:0, 2967 2968 _fromR:0, 2969 _fromG:0, 2970 _fromB:0, 2971 2972 /** 2973 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 2974 * @param {Number} duration duration in seconds 2975 * @param {Number} deltaRed 2976 * @param {Number} deltaGreen 2977 * @param {Number} deltaBlue 2978 */ 2979 ctor:function (duration, deltaRed, deltaGreen, deltaBlue) { 2980 cc.ActionInterval.prototype.ctor.call(this); 2981 deltaBlue !== undefined && this.initWithDuration(duration, deltaRed, deltaGreen, deltaBlue); 2982 }, 2983 2984 /** 2985 * Initializes the action. 2986 * @param {Number} duration 2987 * @param {Number} deltaRed 0-255 2988 * @param {Number} deltaGreen 0-255 2989 * @param {Number} deltaBlue 0-255 2990 * @return {Boolean} 2991 */ 2992 initWithDuration:function (duration, deltaRed, deltaGreen, deltaBlue) { 2993 if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) { 2994 this._deltaR = deltaRed; 2995 this._deltaG = deltaGreen; 2996 this._deltaB = deltaBlue; 2997 return true; 2998 } 2999 return false; 3000 }, 3001 3002 /** 3003 * returns a new clone of the action 3004 * @returns {cc.TintBy} 3005 */ 3006 clone:function () { 3007 var action = new cc.TintBy(); 3008 this._cloneDecoration(action); 3009 action.initWithDuration(this._duration, this._deltaR, this._deltaG, this._deltaB); 3010 return action; 3011 }, 3012 3013 /** 3014 * Start the action with target. 3015 * @param {cc.Node} target 3016 */ 3017 startWithTarget:function (target) { 3018 cc.ActionInterval.prototype.startWithTarget.call(this, target); 3019 3020 var color = target.color; 3021 this._fromR = color.r; 3022 this._fromG = color.g; 3023 this._fromB = color.b; 3024 3025 }, 3026 3027 /** 3028 * Called once per frame. Time is the number of seconds of a frame interval. 3029 * @param {Number} dt time in seconds 3030 */ 3031 update:function (dt) { 3032 dt = this._computeEaseTime(dt); 3033 3034 this.target.color = cc.color(this._fromR + this._deltaR * dt, 3035 this._fromG + this._deltaG * dt, 3036 this._fromB + this._deltaB * dt); 3037 3038 }, 3039 3040 /** 3041 * Returns a reversed action. 3042 * @return {cc.TintBy} 3043 */ 3044 reverse:function () { 3045 var action = new cc.TintBy(this._duration, -this._deltaR, -this._deltaG, -this._deltaB); 3046 this._cloneDecoration(action); 3047 this._reverseEaseList(action); 3048 return action; 3049 } 3050 }); 3051 3052 /** 3053 * Tints a cc.Node that implements the cc.NodeRGB protocol from current tint to a custom one. 3054 * Relative to their own color change. 3055 * @function 3056 * @param {Number} duration duration in seconds 3057 * @param {Number} deltaRed 3058 * @param {Number} deltaGreen 3059 * @param {Number} deltaBlue 3060 * @return {cc.TintBy} 3061 * @example 3062 * // example 3063 * var action = cc.tintBy(2, -127, -255, -127); 3064 */ 3065 cc.tintBy = function (duration, deltaRed, deltaGreen, deltaBlue) { 3066 return new cc.TintBy(duration, deltaRed, deltaGreen, deltaBlue); 3067 }; 3068 /** 3069 * Please use cc.tintBy instead. 3070 * Tints a cc.Node that implements the cc.NodeRGB protocol from current tint to a custom one. 3071 * Relative to their own color change. 3072 * @static 3073 * @deprecated since v3.0 please use cc.tintBy instead. 3074 * @param {Number} duration duration in seconds 3075 * @param {Number} deltaRed 3076 * @param {Number} deltaGreen 3077 * @param {Number} deltaBlue 3078 * @return {cc.TintBy} 3079 */ 3080 cc.TintBy.create = cc.tintBy; 3081 3082 /** Delays the action a certain amount of seconds 3083 * @class 3084 * @extends cc.ActionInterval 3085 */ 3086 cc.DelayTime = cc.ActionInterval.extend(/** @lends cc.DelayTime# */{ 3087 /** 3088 * Called once per frame. Time is the number of seconds of a frame interval. 3089 * Will be overwrite. 3090 * @param {Number} dt time in seconds 3091 */ 3092 update:function (dt) {}, 3093 3094 /** 3095 * Returns a reversed action. 3096 * @return {cc.DelayTime} 3097 */ 3098 reverse:function () { 3099 var action = new cc.DelayTime(this._duration); 3100 this._cloneDecoration(action); 3101 this._reverseEaseList(action); 3102 return action; 3103 }, 3104 3105 /** 3106 * returns a new clone of the action 3107 * @returns {cc.DelayTime} 3108 */ 3109 clone:function () { 3110 var action = new cc.DelayTime(); 3111 this._cloneDecoration(action); 3112 action.initWithDuration(this._duration); 3113 return action; 3114 } 3115 }); 3116 3117 /** 3118 * Delays the action a certain amount of seconds 3119 * @function 3120 * @param {Number} d duration in seconds 3121 * @return {cc.DelayTime} 3122 * @example 3123 * // example 3124 * var delay = cc.delayTime(1); 3125 */ 3126 cc.delayTime = function (d) { 3127 return new cc.DelayTime(d); 3128 }; 3129 /** 3130 * Please use cc.delayTime instead. 3131 * Delays the action a certain amount of seconds 3132 * @static 3133 * @deprecated since v3.0 please use cc.delaTime instead. 3134 * @param {Number} d duration in seconds 3135 * @return {cc.DelayTime} 3136 */ 3137 cc.DelayTime.create = cc.delayTime; 3138 3139 /** 3140 * <p> 3141 * Executes an action in reverse order, from time=duration to time=0 <br/> 3142 * @warning Use this action carefully. This action is not sequenceable. <br/> 3143 * Use it as the default "reversed" method of your own actions, but using it outside the "reversed" <br/> 3144 * scope is not recommended. 3145 * </p> 3146 * @class 3147 * @extends cc.ActionInterval 3148 * @param {cc.FiniteTimeAction} action 3149 * @example 3150 * var reverse = new cc.ReverseTime(this); 3151 */ 3152 cc.ReverseTime = cc.ActionInterval.extend(/** @lends cc.ReverseTime# */{ 3153 _other:null, 3154 3155 /** 3156 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 3157 * @param {cc.FiniteTimeAction} action 3158 */ 3159 ctor:function (action) { 3160 cc.ActionInterval.prototype.ctor.call(this); 3161 this._other = null; 3162 3163 action && this.initWithAction(action); 3164 }, 3165 3166 /** 3167 * @param {cc.FiniteTimeAction} action 3168 * @return {Boolean} 3169 */ 3170 initWithAction:function (action) { 3171 if(!action) 3172 throw new Error("cc.ReverseTime.initWithAction(): action must be non null"); 3173 if(action === this._other) 3174 throw new Error("cc.ReverseTime.initWithAction(): the action was already passed in."); 3175 3176 if (cc.ActionInterval.prototype.initWithDuration.call(this, action._duration)) { 3177 // Don't leak if action is reused 3178 this._other = action; 3179 return true; 3180 } 3181 return false; 3182 }, 3183 3184 /** 3185 * returns a new clone of the action 3186 * @returns {cc.ReverseTime} 3187 */ 3188 clone:function () { 3189 var action = new cc.ReverseTime(); 3190 this._cloneDecoration(action); 3191 action.initWithAction(this._other.clone()); 3192 return action; 3193 }, 3194 3195 /** 3196 * Start the action with target. 3197 * @param {cc.Node} target 3198 */ 3199 startWithTarget:function (target) { 3200 cc.ActionInterval.prototype.startWithTarget.call(this, target); 3201 this._other.startWithTarget(target); 3202 }, 3203 3204 /** 3205 * Called once per frame. Time is the number of seconds of a frame interval. 3206 * @param {Number} dt time in seconds 3207 */ 3208 update:function (dt) { 3209 dt = this._computeEaseTime(dt); 3210 if (this._other) 3211 this._other.update(1 - dt); 3212 }, 3213 3214 /** 3215 * Returns a reversed action. 3216 * @return {cc.ActionInterval} 3217 */ 3218 reverse:function () { 3219 return this._other.clone(); 3220 }, 3221 3222 /** 3223 * Stop the action 3224 */ 3225 stop:function () { 3226 this._other.stop(); 3227 cc.Action.prototype.stop.call(this); 3228 } 3229 }); 3230 3231 /** 3232 * Executes an action in reverse order, from time=duration to time=0. 3233 * @function 3234 * @param {cc.FiniteTimeAction} action 3235 * @return {cc.ReverseTime} 3236 * @example 3237 * // example 3238 * var reverse = cc.reverseTime(this); 3239 */ 3240 cc.reverseTime = function (action) { 3241 return new cc.ReverseTime(action); 3242 }; 3243 /** 3244 * Please use cc.reverseTime instead. 3245 * Executes an action in reverse order, from time=duration to time=0. 3246 * @static 3247 * @deprecated since v3.0 please use cc.reverseTime instead. 3248 * @param {cc.FiniteTimeAction} action 3249 * @return {cc.ReverseTime} 3250 */ 3251 cc.ReverseTime.create = cc.reverseTime; 3252 3253 3254 /** Animates a sprite given the name of an Animation 3255 * @class 3256 * @extends cc.ActionInterval 3257 * @param {cc.Animation} animation 3258 * @example 3259 * // create the animation with animation 3260 * var anim = new cc.Animate(dance_grey); 3261 */ 3262 cc.Animate = cc.ActionInterval.extend(/** @lends cc.Animate# */{ 3263 _animation:null, 3264 _nextFrame:0, 3265 _origFrame:null, 3266 _executedLoops:0, 3267 _splitTimes: null, 3268 _currFrameIndex:0, 3269 3270 /** 3271 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br /> 3272 * create the animate with animation. 3273 * @param {cc.Animation} animation 3274 */ 3275 ctor:function (animation) { 3276 cc.ActionInterval.prototype.ctor.call(this); 3277 this._splitTimes = []; 3278 3279 animation && this.initWithAnimation(animation); 3280 }, 3281 3282 /** 3283 * @return {cc.Animation} 3284 */ 3285 getAnimation:function () { 3286 return this._animation; 3287 }, 3288 3289 /** 3290 * @param {cc.Animation} animation 3291 */ 3292 setAnimation:function (animation) { 3293 this._animation = animation; 3294 }, 3295 3296 /** 3297 * Gets the index of sprite frame currently displayed. 3298 * @return {Number} 3299 */ 3300 getCurrentFrameIndex: function () { 3301 return this._currFrameIndex; 3302 }, 3303 3304 /** 3305 * @param {cc.Animation} animation 3306 * @return {Boolean} 3307 */ 3308 initWithAnimation:function (animation) { 3309 if(!animation) 3310 throw new Error("cc.Animate.initWithAnimation(): animation must be non-NULL"); 3311 var singleDuration = animation.getDuration(); 3312 if (this.initWithDuration(singleDuration * animation.getLoops())) { 3313 this._nextFrame = 0; 3314 this.setAnimation(animation); 3315 3316 this._origFrame = null; 3317 this._executedLoops = 0; 3318 var locTimes = this._splitTimes; 3319 locTimes.length = 0; 3320 3321 var accumUnitsOfTime = 0; 3322 var newUnitOfTimeValue = singleDuration / animation.getTotalDelayUnits(); 3323 3324 var frames = animation.getFrames(); 3325 cc.arrayVerifyType(frames, cc.AnimationFrame); 3326 3327 for (var i = 0; i < frames.length; i++) { 3328 var frame = frames[i]; 3329 var value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration; 3330 accumUnitsOfTime += frame.getDelayUnits(); 3331 locTimes.push(value); 3332 } 3333 return true; 3334 } 3335 return false; 3336 }, 3337 3338 /** 3339 * returns a new clone of the action 3340 * @returns {cc.Animate} 3341 */ 3342 clone:function () { 3343 var action = new cc.Animate(); 3344 this._cloneDecoration(action); 3345 action.initWithAnimation(this._animation.clone()); 3346 return action; 3347 }, 3348 3349 /** 3350 * Start the action with target. 3351 * @param {cc.Sprite} target 3352 */ 3353 startWithTarget:function (target) { 3354 cc.ActionInterval.prototype.startWithTarget.call(this, target); 3355 if (this._animation.getRestoreOriginalFrame()) 3356 this._origFrame = target.displayFrame(); 3357 this._nextFrame = 0; 3358 this._executedLoops = 0; 3359 }, 3360 3361 /** 3362 * Called once per frame. Time is the number of seconds of a frame interval. 3363 * @param {Number} dt 3364 */ 3365 update:function (dt) { 3366 dt = this._computeEaseTime(dt); 3367 // if t==1, ignore. Animation should finish with t==1 3368 if (dt < 1.0) { 3369 dt *= this._animation.getLoops(); 3370 3371 // new loop? If so, reset frame counter 3372 var loopNumber = 0 | dt; 3373 if (loopNumber > this._executedLoops) { 3374 this._nextFrame = 0; 3375 this._executedLoops++; 3376 } 3377 3378 // new t for animations 3379 dt = dt % 1.0; 3380 } 3381 3382 var frames = this._animation.getFrames(); 3383 var numberOfFrames = frames.length, locSplitTimes = this._splitTimes; 3384 for (var i = this._nextFrame; i < numberOfFrames; i++) { 3385 if (locSplitTimes[i] <= dt) { 3386 _currFrameIndex = i; 3387 this.target.setSpriteFrame(frames[_currFrameIndex].getSpriteFrame()); 3388 this._nextFrame = i + 1; 3389 } else { 3390 // Issue 1438. Could be more than one frame per tick, due to low frame rate or frame delta < 1/FPS 3391 break; 3392 } 3393 } 3394 }, 3395 3396 /** 3397 * Returns a reversed action. 3398 * @return {cc.Animate} 3399 */ 3400 reverse:function () { 3401 var locAnimation = this._animation; 3402 var oldArray = locAnimation.getFrames(); 3403 var newArray = []; 3404 cc.arrayVerifyType(oldArray, cc.AnimationFrame); 3405 if (oldArray.length > 0) { 3406 for (var i = oldArray.length - 1; i >= 0; i--) { 3407 var element = oldArray[i]; 3408 if (!element) 3409 break; 3410 newArray.push(element.clone()); 3411 } 3412 } 3413 var newAnim = new cc.Animation(newArray, locAnimation.getDelayPerUnit(), locAnimation.getLoops()); 3414 newAnim.setRestoreOriginalFrame(locAnimation.getRestoreOriginalFrame()); 3415 var action = new cc.Animate(newAnim); 3416 this._cloneDecoration(action); 3417 this._reverseEaseList(action); 3418 3419 return action; 3420 }, 3421 3422 /** 3423 * stop the action 3424 */ 3425 stop:function () { 3426 if (this._animation.getRestoreOriginalFrame() && this.target) 3427 this.target.setSpriteFrame(this._origFrame); 3428 cc.Action.prototype.stop.call(this); 3429 } 3430 }); 3431 3432 /** 3433 * create the animate with animation 3434 * @function 3435 * @param {cc.Animation} animation 3436 * @return {cc.Animate} 3437 * @example 3438 * // example 3439 * // create the animation with animation 3440 * var anim = cc.animate(dance_grey); 3441 */ 3442 cc.animate = function (animation) { 3443 return new cc.Animate(animation); 3444 }; 3445 /** 3446 * Please use cc.animate instead 3447 * create the animate with animation 3448 * @static 3449 * @deprecated since v3.0 please use cc.animate instead. 3450 * @param {cc.Animation} animation 3451 * @return {cc.Animate} 3452 */ 3453 cc.Animate.create = cc.animate; 3454 3455 /** 3456 * <p> 3457 * Overrides the target of an action so that it always runs on the target<br/> 3458 * specified at action creation rather than the one specified by runAction. 3459 * </p> 3460 * @class 3461 * @extends cc.ActionInterval 3462 * @param {cc.Node} target 3463 * @param {cc.FiniteTimeAction} action 3464 */ 3465 cc.TargetedAction = cc.ActionInterval.extend(/** @lends cc.TargetedAction# */{ 3466 _action:null, 3467 _forcedTarget:null, 3468 3469 /** 3470 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br /> 3471 * Create an action with the specified action and forced target. 3472 * @param {cc.Node} target 3473 * @param {cc.FiniteTimeAction} action 3474 */ 3475 ctor: function (target, action) { 3476 cc.ActionInterval.prototype.ctor.call(this); 3477 action && this.initWithTarget(target, action); 3478 }, 3479 3480 /** 3481 * Init an action with the specified action and forced target 3482 * @param {cc.Node} target 3483 * @param {cc.FiniteTimeAction} action 3484 * @return {Boolean} 3485 */ 3486 initWithTarget:function (target, action) { 3487 if (this.initWithDuration(action._duration)) { 3488 this._forcedTarget = target; 3489 this._action = action; 3490 return true; 3491 } 3492 return false; 3493 }, 3494 3495 /** 3496 * returns a new clone of the action 3497 * @returns {cc.TargetedAction} 3498 */ 3499 clone:function () { 3500 var action = new cc.TargetedAction(); 3501 this._cloneDecoration(action); 3502 action.initWithTarget(this._forcedTarget, this._action.clone()); 3503 return action; 3504 }, 3505 3506 /** 3507 * Start the action with target. 3508 * @param {cc.Node} target 3509 */ 3510 startWithTarget:function (target) { 3511 cc.ActionInterval.prototype.startWithTarget.call(this, target); 3512 this._action.startWithTarget(this._forcedTarget); 3513 }, 3514 3515 /** 3516 * stop the action 3517 */ 3518 stop:function () { 3519 this._action.stop(); 3520 }, 3521 3522 /** 3523 * Called once per frame. Time is the number of seconds of a frame interval. 3524 * @param {Number} dt 3525 */ 3526 update:function (dt) { 3527 dt = this._computeEaseTime(dt); 3528 this._action.update(dt); 3529 }, 3530 3531 /** 3532 * return the target that the action will be forced to run with 3533 * @return {cc.Node} 3534 */ 3535 getForcedTarget:function () { 3536 return this._forcedTarget; 3537 }, 3538 3539 /** 3540 * set the target that the action will be forced to run with 3541 * @param {cc.Node} forcedTarget 3542 */ 3543 setForcedTarget:function (forcedTarget) { 3544 if (this._forcedTarget !== forcedTarget) 3545 this._forcedTarget = forcedTarget; 3546 } 3547 }); 3548 3549 /** 3550 * Create an action with the specified action and forced target 3551 * @function 3552 * @param {cc.Node} target 3553 * @param {cc.FiniteTimeAction} action 3554 * @return {cc.TargetedAction} 3555 */ 3556 cc.targetedAction = function (target, action) { 3557 return new cc.TargetedAction(target, action); 3558 }; 3559 /** 3560 * Please use cc.targetedAction instead 3561 * Create an action with the specified action and forced target 3562 * @static 3563 * @deprecated since v3.0 please use cc.targetedAction instead. 3564 * @param {cc.Node} target 3565 * @param {cc.FiniteTimeAction} action 3566 * @return {cc.TargetedAction} 3567 */ 3568 cc.TargetedAction.create = cc.targetedAction; 3569