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 {null} 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 */ 1125 reverse:function () { 1126 cc.log("cc.RotateTo.reverse(): it should be overridden in subclass."); 1127 }, 1128 1129 /** 1130 * Called once per frame. Time is the number of seconds of a frame interval. 1131 * @param {Number} dt 1132 */ 1133 update:function (dt) { 1134 dt = this._computeEaseTime(dt); 1135 if (this.target) { 1136 this.target.rotationX = this._startAngleX + this._diffAngleX * dt; 1137 this.target.rotationY = this._startAngleY + this._diffAngleY * dt; 1138 } 1139 } 1140 }); 1141 1142 /** 1143 * Creates a RotateTo action with separate rotation angles. 1144 * To specify the angle of rotation. 1145 * @function 1146 * @param {Number} duration duration in seconds 1147 * @param {Number} deltaAngleX deltaAngleX in degrees. 1148 * @param {Number} [deltaAngleY] deltaAngleY in degrees. 1149 * @return {cc.RotateTo} 1150 * @example 1151 * // example 1152 * var rotateTo = cc.rotateTo(2, 61.0); 1153 */ 1154 cc.rotateTo = function (duration, deltaAngleX, deltaAngleY) { 1155 return new cc.RotateTo(duration, deltaAngleX, deltaAngleY); 1156 }; 1157 1158 /** 1159 * Please use cc.rotateTo instead 1160 * Creates a RotateTo action with separate rotation angles. 1161 * To specify the angle of rotation. 1162 * @static 1163 * @deprecated since v3.0 <br /> Please use cc.rotateTo instead. 1164 * @param {Number} duration duration in seconds 1165 * @param {Number} deltaAngleX deltaAngleX in degrees. 1166 * @param {Number} [deltaAngleY] deltaAngleY in degrees. 1167 * @return {cc.RotateTo} 1168 */ 1169 cc.RotateTo.create = cc.rotateTo; 1170 1171 1172 /** 1173 * Rotates a cc.Node object clockwise a number of degrees by modifying it's rotation attribute. 1174 * Relative to its properties to modify. 1175 * @class 1176 * @extends cc.ActionInterval 1177 * @param {Number} duration duration in seconds 1178 * @param {Number} deltaAngleX deltaAngleX in degrees 1179 * @param {Number} [deltaAngleY] deltaAngleY in degrees 1180 * @example 1181 * var actionBy = new cc.RotateBy(2, 360); 1182 */ 1183 cc.RotateBy = cc.ActionInterval.extend(/** @lends cc.RotateBy# */{ 1184 _angleX:0, 1185 _startAngleX:0, 1186 _angleY:0, 1187 _startAngleY:0, 1188 1189 /** 1190 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 1191 * @param {Number} duration duration in seconds 1192 * @param {Number} deltaAngleX deltaAngleX in degrees 1193 * @param {Number} [deltaAngleY] deltaAngleY in degrees 1194 */ 1195 ctor: function (duration, deltaAngleX, deltaAngleY) { 1196 cc.ActionInterval.prototype.ctor.call(this); 1197 1198 deltaAngleX !== undefined && this.initWithDuration(duration, deltaAngleX, deltaAngleY); 1199 }, 1200 1201 /** 1202 * Initializes the action. 1203 * @param {Number} duration duration in seconds 1204 * @param {Number} deltaAngleX deltaAngleX in degrees 1205 * @param {Number} [deltaAngleY=] deltaAngleY in degrees 1206 * @return {Boolean} 1207 */ 1208 initWithDuration:function (duration, deltaAngleX, deltaAngleY) { 1209 if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) { 1210 this._angleX = deltaAngleX || 0; 1211 this._angleY = deltaAngleY || this._angleX; 1212 return true; 1213 } 1214 return false; 1215 }, 1216 1217 /** 1218 * returns a new clone of the action 1219 * @returns {cc.RotateBy} 1220 */ 1221 clone:function () { 1222 var action = new cc.RotateBy(); 1223 this._cloneDecoration(action); 1224 action.initWithDuration(this._duration, this._angleX, this._angleY); 1225 return action; 1226 }, 1227 1228 /** 1229 * Start the action with target. 1230 * @param {cc.Node} target 1231 */ 1232 startWithTarget:function (target) { 1233 cc.ActionInterval.prototype.startWithTarget.call(this, target); 1234 this._startAngleX = target.rotationX; 1235 this._startAngleY = target.rotationY; 1236 }, 1237 1238 /** 1239 * Called once per frame. Time is the number of seconds of a frame interval. 1240 * @param {Number} dt 1241 */ 1242 update:function (dt) { 1243 dt = this._computeEaseTime(dt); 1244 if (this.target) { 1245 this.target.rotationX = this._startAngleX + this._angleX * dt; 1246 this.target.rotationY = this._startAngleY + this._angleY * dt; 1247 } 1248 }, 1249 1250 /** 1251 * Returns a reversed action. 1252 * @return {cc.RotateBy} 1253 */ 1254 reverse:function () { 1255 var action = new cc.RotateBy(this._duration, -this._angleX, -this._angleY); 1256 this._cloneDecoration(action); 1257 this._reverseEaseList(action); 1258 return action; 1259 } 1260 }); 1261 1262 /** 1263 * Rotates a cc.Node object clockwise a number of degrees by modifying it's rotation attribute. 1264 * Relative to its properties to modify. 1265 * @function 1266 * @param {Number} duration duration in seconds 1267 * @param {Number} deltaAngleX deltaAngleX in degrees 1268 * @param {Number} [deltaAngleY] deltaAngleY in degrees 1269 * @return {cc.RotateBy} 1270 * @example 1271 * // example 1272 * var actionBy = cc.rotateBy(2, 360); 1273 */ 1274 cc.rotateBy = function (duration, deltaAngleX, deltaAngleY) { 1275 return new cc.RotateBy(duration, deltaAngleX, deltaAngleY); 1276 }; 1277 /** 1278 * Please use cc.rotateBy instead. 1279 * Rotates a cc.Node object clockwise a number of degrees by modifying it's rotation attribute. 1280 * Relative to its properties to modify. 1281 * @static 1282 * @deprecated since v3.0 <br /> Please use cc.rotateBy instead. 1283 * @param {Number} duration duration in seconds 1284 * @param {Number} deltaAngleX deltaAngleX in degrees 1285 * @param {Number} [deltaAngleY] deltaAngleY in degrees 1286 * @return {cc.RotateBy} 1287 */ 1288 cc.RotateBy.create = cc.rotateBy; 1289 1290 1291 /** 1292 * <p> 1293 * Moves a CCNode object x,y pixels by modifying it's position attribute. <br/> 1294 * x and y are relative to the position of the object. <br/> 1295 * Several CCMoveBy actions can be concurrently called, and the resulting <br/> 1296 * movement will be the sum of individual movements. 1297 * </p> 1298 * @class 1299 * @extends cc.ActionInterval 1300 * @param {Number} duration duration in seconds 1301 * @param {cc.Point|Number} deltaPos 1302 * @param {Number} [deltaY] 1303 * @example 1304 * var actionTo = cc.moveBy(2, cc.p(windowSize.width - 40, windowSize.height - 40)); 1305 */ 1306 cc.MoveBy = cc.ActionInterval.extend(/** @lends cc.MoveBy# */{ 1307 _positionDelta:null, 1308 _startPosition:null, 1309 _previousPosition:null, 1310 1311 /** 1312 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 1313 * @param {Number} duration duration in seconds 1314 * @param {cc.Point|Number} deltaPos 1315 * @param {Number} [deltaY] 1316 */ 1317 ctor:function (duration, deltaPos, deltaY) { 1318 cc.ActionInterval.prototype.ctor.call(this); 1319 1320 this._positionDelta = cc.p(0, 0); 1321 this._startPosition = cc.p(0, 0); 1322 this._previousPosition = cc.p(0, 0); 1323 1324 deltaPos !== undefined && this.initWithDuration(duration, deltaPos, deltaY); 1325 }, 1326 1327 /** 1328 * Initializes the action. 1329 * @param {Number} duration duration in seconds 1330 * @param {cc.Point} position 1331 * @param {Number} [y] 1332 * @return {Boolean} 1333 */ 1334 initWithDuration:function (duration, position, y) { 1335 if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) { 1336 if(position.x !== undefined) { 1337 y = position.y; 1338 position = position.x; 1339 } 1340 1341 this._positionDelta.x = position; 1342 this._positionDelta.y = y; 1343 return true; 1344 } 1345 return false; 1346 }, 1347 1348 /** 1349 * returns a new clone of the action 1350 * @returns {cc.MoveBy} 1351 */ 1352 clone:function () { 1353 var action = new cc.MoveBy(); 1354 this._cloneDecoration(action); 1355 action.initWithDuration(this._duration, this._positionDelta); 1356 return action; 1357 }, 1358 1359 /** 1360 * Start the action with target. 1361 * @param {cc.Node} target 1362 */ 1363 startWithTarget:function (target) { 1364 cc.ActionInterval.prototype.startWithTarget.call(this, target); 1365 var locPosX = target.getPositionX(); 1366 var locPosY = target.getPositionY(); 1367 this._previousPosition.x = locPosX; 1368 this._previousPosition.y = locPosY; 1369 this._startPosition.x = locPosX; 1370 this._startPosition.y = locPosY; 1371 }, 1372 1373 /** 1374 * Called once per frame. Time is the number of seconds of a frame interval. 1375 * @param {Number} dt 1376 */ 1377 update:function (dt) { 1378 dt = this._computeEaseTime(dt); 1379 if (this.target) { 1380 var x = this._positionDelta.x * dt; 1381 var y = this._positionDelta.y * dt; 1382 var locStartPosition = this._startPosition; 1383 if (cc.ENABLE_STACKABLE_ACTIONS) { 1384 var targetX = this.target.getPositionX(); 1385 var targetY = this.target.getPositionY(); 1386 var locPreviousPosition = this._previousPosition; 1387 1388 locStartPosition.x = locStartPosition.x + targetX - locPreviousPosition.x; 1389 locStartPosition.y = locStartPosition.y + targetY - locPreviousPosition.y; 1390 x = x + locStartPosition.x; 1391 y = y + locStartPosition.y; 1392 locPreviousPosition.x = x; 1393 locPreviousPosition.y = y; 1394 this.target.setPosition(x, y); 1395 } else { 1396 this.target.setPosition(locStartPosition.x + x, locStartPosition.y + y); 1397 } 1398 } 1399 }, 1400 1401 /** 1402 * MoveTo reverse is not implemented 1403 * @return {cc.MoveBy} 1404 */ 1405 reverse:function () { 1406 var action = new cc.MoveBy(this._duration, cc.p(-this._positionDelta.x, -this._positionDelta.y)); 1407 this._cloneDecoration(action); 1408 this._reverseEaseList(action); 1409 return action; 1410 } 1411 }); 1412 1413 /** 1414 * Create the action. 1415 * Relative to its coordinate moves a certain distance. 1416 * @function 1417 * @param {Number} duration duration in seconds 1418 * @param {cc.Point|Number} deltaPos 1419 * @param {Number} deltaY 1420 * @return {cc.MoveBy} 1421 * @example 1422 * // example 1423 * var actionTo = cc.moveBy(2, cc.p(windowSize.width - 40, windowSize.height - 40)); 1424 */ 1425 cc.moveBy = function (duration, deltaPos, deltaY) { 1426 return new cc.MoveBy(duration, deltaPos, deltaY); 1427 }; 1428 /** 1429 * Please use cc.moveBy instead. 1430 * Relative to its coordinate moves a certain distance. 1431 * @static 1432 * @deprecated since v3.0 please use cc.moveBy instead. 1433 * @param {Number} duration duration in seconds 1434 * @param {cc.Point|Number} deltaPos 1435 * @param {Number} deltaY 1436 * @return {cc.MoveBy} 1437 */ 1438 cc.MoveBy.create = cc.moveBy; 1439 1440 1441 /** 1442 * Moves a CCNode object to the position x,y. x and y are absolute coordinates by modifying it's position attribute. <br/> 1443 * Several CCMoveTo actions can be concurrently called, and the resulting <br/> 1444 * movement will be the sum of individual movements. 1445 * @class 1446 * @extends cc.MoveBy 1447 * @param {Number} duration duration in seconds 1448 * @param {cc.Point|Number} position 1449 * @param {Number} y 1450 * @example 1451 * var actionBy = new cc.MoveTo(2, cc.p(80, 80)); 1452 */ 1453 cc.MoveTo = cc.MoveBy.extend(/** @lends cc.MoveTo# */{ 1454 _endPosition:null, 1455 1456 /** 1457 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 1458 * @param {Number} duration duration in seconds 1459 * @param {cc.Point|Number} position 1460 * @param {Number} y 1461 */ 1462 ctor:function (duration, position, y) { 1463 cc.MoveBy.prototype.ctor.call(this); 1464 this._endPosition = cc.p(0, 0); 1465 1466 position !== undefined && this.initWithDuration(duration, position, y); 1467 }, 1468 1469 /** 1470 * Initializes the action. 1471 * @param {Number} duration duration in seconds 1472 * @param {cc.Point} position 1473 * @param {Number} y 1474 * @return {Boolean} 1475 */ 1476 initWithDuration:function (duration, position, y) { 1477 if (cc.MoveBy.prototype.initWithDuration.call(this, duration, position, y)) { 1478 if(position.x !== undefined) { 1479 y = position.y; 1480 position = position.x; 1481 } 1482 1483 this._endPosition.x = position; 1484 this._endPosition.y = y; 1485 return true; 1486 } 1487 return false; 1488 }, 1489 1490 /** 1491 * returns a new clone of the action 1492 * @returns {cc.MoveTo} 1493 */ 1494 clone:function () { 1495 var action = new cc.MoveTo(); 1496 this._cloneDecoration(action); 1497 action.initWithDuration(this._duration, this._endPosition); 1498 return action; 1499 }, 1500 1501 /** 1502 * Start the action with target. 1503 * @param {cc.Node} target 1504 */ 1505 startWithTarget:function (target) { 1506 cc.MoveBy.prototype.startWithTarget.call(this, target); 1507 this._positionDelta.x = this._endPosition.x - target.getPositionX(); 1508 this._positionDelta.y = this._endPosition.y - target.getPositionY(); 1509 } 1510 }); 1511 1512 /** 1513 * Create new action. 1514 * Moving to the specified coordinates. 1515 * @function 1516 * @param {Number} duration duration in seconds 1517 * @param {cc.Point} position 1518 * @param {Number} y 1519 * @return {cc.MoveBy} 1520 * @example 1521 * // example 1522 * var actionBy = cc.moveTo(2, cc.p(80, 80)); 1523 */ 1524 cc.moveTo = function (duration, position, y) { 1525 return new cc.MoveTo(duration, position, y); 1526 }; 1527 /** 1528 * Please use cc.moveTo instead. 1529 * Moving to the specified coordinates. 1530 * @static 1531 * @deprecated since v3.0 <br /> Please use cc.moveTo instead. 1532 * @param {Number} duration duration in seconds 1533 * @param {cc.Point} position 1534 * @param {Number} y 1535 * @return {cc.MoveBy} 1536 */ 1537 cc.MoveTo.create = cc.moveTo; 1538 1539 /** 1540 * Skews a cc.Node object to given angles by modifying it's skewX and skewY attributes 1541 * @class 1542 * @extends cc.ActionInterval 1543 * @param {Number} t time in seconds 1544 * @param {Number} sx 1545 * @param {Number} sy 1546 * @example 1547 * var actionTo = new cc.SkewTo(2, 37.2, -37.2); 1548 */ 1549 cc.SkewTo = cc.ActionInterval.extend(/** @lends cc.SkewTo# */{ 1550 _skewX:0, 1551 _skewY:0, 1552 _startSkewX:0, 1553 _startSkewY:0, 1554 _endSkewX:0, 1555 _endSkewY:0, 1556 _deltaX:0, 1557 _deltaY:0, 1558 1559 /** 1560 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 1561 * @param {Number} t time in seconds 1562 * @param {Number} sx 1563 * @param {Number} sy 1564 */ 1565 ctor: function (t, sx, sy) { 1566 cc.ActionInterval.prototype.ctor.call(this); 1567 1568 sy !== undefined && this.initWithDuration(t, sx, sy); 1569 }, 1570 1571 /** 1572 * Initializes the action. 1573 * @param {Number} t time in seconds 1574 * @param {Number} sx 1575 * @param {Number} sy 1576 * @return {Boolean} 1577 */ 1578 initWithDuration:function (t, sx, sy) { 1579 var ret = false; 1580 if (cc.ActionInterval.prototype.initWithDuration.call(this, t)) { 1581 this._endSkewX = sx; 1582 this._endSkewY = sy; 1583 ret = true; 1584 } 1585 return ret; 1586 }, 1587 1588 /** 1589 * returns a new clone of the action 1590 * @returns {cc.SkewTo} 1591 */ 1592 clone:function () { 1593 var action = new cc.SkewTo(); 1594 this._cloneDecoration(action); 1595 action.initWithDuration(this._duration, this._endSkewX, this._endSkewY); 1596 return action; 1597 }, 1598 1599 /** 1600 * Start the action with target. 1601 * @param {cc.Node} target 1602 */ 1603 startWithTarget:function (target) { 1604 cc.ActionInterval.prototype.startWithTarget.call(this, target); 1605 1606 this._startSkewX = target.skewX % 180; 1607 this._deltaX = this._endSkewX - this._startSkewX; 1608 if (this._deltaX > 180) 1609 this._deltaX -= 360; 1610 if (this._deltaX < -180) 1611 this._deltaX += 360; 1612 1613 this._startSkewY = target.skewY % 360; 1614 this._deltaY = this._endSkewY - this._startSkewY; 1615 if (this._deltaY > 180) 1616 this._deltaY -= 360; 1617 if (this._deltaY < -180) 1618 this._deltaY += 360; 1619 }, 1620 1621 /** 1622 * Called once per frame. Time is the number of seconds of a frame interval. 1623 * @param {Number} dt 1624 */ 1625 update:function (dt) { 1626 dt = this._computeEaseTime(dt); 1627 this.target.skewX = this._startSkewX + this._deltaX * dt; 1628 this.target.skewY = this._startSkewY + this._deltaY * dt; 1629 } 1630 }); 1631 /** 1632 * Create new action. 1633 * Skews a cc.Node object to given angles by modifying it's skewX and skewY attributes. 1634 * Changes to the specified value. 1635 * @function 1636 * @param {Number} t time in seconds 1637 * @param {Number} sx 1638 * @param {Number} sy 1639 * @return {cc.SkewTo} 1640 * @example 1641 * // example 1642 * var actionTo = cc.skewTo(2, 37.2, -37.2); 1643 */ 1644 cc.skewTo = function (t, sx, sy) { 1645 return new cc.SkewTo(t, sx, sy); 1646 }; 1647 /** 1648 * Please use cc.skewTo instead. 1649 * Skews a cc.Node object to given angles by modifying it's skewX and skewY attributes。 1650 * Changes to the specified value. 1651 * @static 1652 * @deprecated since v3.0 <br /> Please use cc.skewTo instead. 1653 * @param {Number} t time in seconds 1654 * @param {Number} sx 1655 * @param {Number} sy 1656 * @return {cc.SkewTo} 1657 */ 1658 cc.SkewTo.create = cc.skewTo; 1659 1660 /** 1661 * Skews a cc.Node object by skewX and skewY degrees. 1662 * Relative to its attribute modification. 1663 * @class 1664 * @extends cc.SkewTo 1665 * @param {Number} t time in seconds 1666 * @param {Number} sx skew in degrees for X axis 1667 * @param {Number} sy skew in degrees for Y axis 1668 */ 1669 cc.SkewBy = cc.SkewTo.extend(/** @lends cc.SkewBy# */{ 1670 1671 /** 1672 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 1673 * @param {Number} t time in seconds 1674 * @param {Number} sx skew in degrees for X axis 1675 * @param {Number} sy skew in degrees for Y axis 1676 */ 1677 ctor: function(t, sx, sy) { 1678 cc.SkewTo.prototype.ctor.call(this); 1679 sy !== undefined && this.initWithDuration(t, sx, sy); 1680 }, 1681 1682 /** 1683 * Initializes the action. 1684 * @param {Number} t time in seconds 1685 * @param {Number} deltaSkewX skew in degrees for X axis 1686 * @param {Number} deltaSkewY skew in degrees for Y axis 1687 * @return {Boolean} 1688 */ 1689 initWithDuration:function (t, deltaSkewX, deltaSkewY) { 1690 var ret = false; 1691 if (cc.SkewTo.prototype.initWithDuration.call(this, t, deltaSkewX, deltaSkewY)) { 1692 this._skewX = deltaSkewX; 1693 this._skewY = deltaSkewY; 1694 ret = true; 1695 } 1696 return ret; 1697 }, 1698 1699 /** 1700 * returns a new clone of the action 1701 * @returns {cc.SkewBy} 1702 */ 1703 clone:function () { 1704 var action = new cc.SkewBy(); 1705 this._cloneDecoration(action); 1706 action.initWithDuration(this._duration, this._skewX, this._skewY); 1707 return action; 1708 }, 1709 1710 /** 1711 * Start the action width target. 1712 * @param {cc.Node} target 1713 */ 1714 startWithTarget:function (target) { 1715 cc.SkewTo.prototype.startWithTarget.call(this, target); 1716 this._deltaX = this._skewX; 1717 this._deltaY = this._skewY; 1718 this._endSkewX = this._startSkewX + this._deltaX; 1719 this._endSkewY = this._startSkewY + this._deltaY; 1720 }, 1721 1722 /** 1723 * Returns a reversed action. 1724 * @return {cc.SkewBy} 1725 */ 1726 reverse:function () { 1727 var action = new cc.SkewBy(this._duration, -this._skewX, -this._skewY); 1728 this._cloneDecoration(action); 1729 this._reverseEaseList(action); 1730 return action; 1731 } 1732 }); 1733 1734 /** 1735 * Skews a cc.Node object by skewX and skewY degrees. <br /> 1736 * Relative to its attribute modification. 1737 * @function 1738 * @param {Number} t time in seconds 1739 * @param {Number} sx sx skew in degrees for X axis 1740 * @param {Number} sy sy skew in degrees for Y axis 1741 * @return {cc.SkewBy} 1742 * @example 1743 * // example 1744 * var actionBy = cc.skewBy(2, 0, -90); 1745 */ 1746 cc.skewBy = function (t, sx, sy) { 1747 return new cc.SkewBy(t, sx, sy); 1748 }; 1749 /** 1750 * Please use cc.skewBy instead. <br /> 1751 * Skews a cc.Node object by skewX and skewY degrees. <br /> 1752 * Relative to its attribute modification. 1753 * @static 1754 * @deprecated since v3.0 please use cc.skewBy instead. 1755 * @param {Number} t time in seconds 1756 * @param {Number} sx sx skew in degrees for X axis 1757 * @param {Number} sy sy skew in degrees for Y axis 1758 * @return {cc.SkewBy} 1759 */ 1760 cc.SkewBy.create = cc.skewBy; 1761 1762 1763 /** 1764 * Moves a cc.Node object simulating a parabolic jump movement by modifying it's position attribute. 1765 * Relative to its movement. 1766 * @class 1767 * @extends cc.ActionInterval 1768 * @param {Number} duration 1769 * @param {cc.Point|Number} position 1770 * @param {Number} [y] 1771 * @param {Number} height 1772 * @param {Number} jumps 1773 * @example 1774 * var actionBy = new cc.JumpBy(2, cc.p(300, 0), 50, 4); 1775 * var actionBy = new cc.JumpBy(2, 300, 0, 50, 4); 1776 */ 1777 cc.JumpBy = cc.ActionInterval.extend(/** @lends cc.JumpBy# */{ 1778 _startPosition:null, 1779 _delta:null, 1780 _height:0, 1781 _jumps:0, 1782 _previousPosition:null, 1783 1784 /** 1785 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 1786 * @param {Number} duration 1787 * @param {cc.Point|Number} position 1788 * @param {Number} [y] 1789 * @param {Number} height 1790 * @param {Number} jumps 1791 */ 1792 ctor:function (duration, position, y, height, jumps) { 1793 cc.ActionInterval.prototype.ctor.call(this); 1794 this._startPosition = cc.p(0, 0); 1795 this._previousPosition = cc.p(0, 0); 1796 this._delta = cc.p(0, 0); 1797 1798 height !== undefined && this.initWithDuration(duration, position, y, height, jumps); 1799 }, 1800 /** 1801 * Initializes the action. 1802 * @param {Number} duration 1803 * @param {cc.Point|Number} position 1804 * @param {Number} [y] 1805 * @param {Number} height 1806 * @param {Number} jumps 1807 * @return {Boolean} 1808 * @example 1809 * actionBy.initWithDuration(2, cc.p(300, 0), 50, 4); 1810 * actionBy.initWithDuration(2, 300, 0, 50, 4); 1811 */ 1812 initWithDuration:function (duration, position, y, height, jumps) { 1813 if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) { 1814 if (jumps === undefined) { 1815 jumps = height; 1816 height = y; 1817 y = position.y; 1818 position = position.x; 1819 } 1820 this._delta.x = position; 1821 this._delta.y = y; 1822 this._height = height; 1823 this._jumps = jumps; 1824 return true; 1825 } 1826 return false; 1827 }, 1828 1829 /** 1830 * returns a new clone of the action 1831 * @returns {cc.JumpBy} 1832 */ 1833 clone:function () { 1834 var action = new cc.JumpBy(); 1835 this._cloneDecoration(action); 1836 action.initWithDuration(this._duration, this._delta, this._height, this._jumps); 1837 return action; 1838 }, 1839 1840 /** 1841 * Start the action with target. 1842 * @param {cc.Node} target 1843 */ 1844 startWithTarget:function (target) { 1845 cc.ActionInterval.prototype.startWithTarget.call(this, target); 1846 var locPosX = target.getPositionX(); 1847 var locPosY = target.getPositionY(); 1848 this._previousPosition.x = locPosX; 1849 this._previousPosition.y = locPosY; 1850 this._startPosition.x = locPosX; 1851 this._startPosition.y = locPosY; 1852 }, 1853 1854 /** 1855 * Called once per frame. Time is the number of seconds of a frame interval. 1856 * @param {Number} dt 1857 */ 1858 update:function (dt) { 1859 dt = this._computeEaseTime(dt); 1860 if (this.target) { 1861 var frac = dt * this._jumps % 1.0; 1862 var y = this._height * 4 * frac * (1 - frac); 1863 y += this._delta.y * dt; 1864 1865 var x = this._delta.x * dt; 1866 var locStartPosition = this._startPosition; 1867 if (cc.ENABLE_STACKABLE_ACTIONS) { 1868 var targetX = this.target.getPositionX(); 1869 var targetY = this.target.getPositionY(); 1870 var locPreviousPosition = this._previousPosition; 1871 1872 locStartPosition.x = locStartPosition.x + targetX - locPreviousPosition.x; 1873 locStartPosition.y = locStartPosition.y + targetY - locPreviousPosition.y; 1874 x = x + locStartPosition.x; 1875 y = y + locStartPosition.y; 1876 locPreviousPosition.x = x; 1877 locPreviousPosition.y = y; 1878 this.target.setPosition(x, y); 1879 } else { 1880 this.target.setPosition(locStartPosition.x + x, locStartPosition.y + y); 1881 } 1882 } 1883 }, 1884 1885 /** 1886 * Returns a reversed action. 1887 * @return {cc.JumpBy} 1888 */ 1889 reverse:function () { 1890 var action = new cc.JumpBy(this._duration, cc.p(-this._delta.x, -this._delta.y), this._height, this._jumps); 1891 this._cloneDecoration(action); 1892 this._reverseEaseList(action); 1893 return action; 1894 } 1895 }); 1896 1897 /** 1898 * Moves a cc.Node object simulating a parabolic jump movement by modifying it's position attribute. 1899 * Relative to its movement. 1900 * @function 1901 * @param {Number} duration 1902 * @param {cc.Point|Number} position 1903 * @param {Number} [y] 1904 * @param {Number} height 1905 * @param {Number} jumps 1906 * @return {cc.JumpBy} 1907 * @example 1908 * // example 1909 * var actionBy = cc.jumpBy(2, cc.p(300, 0), 50, 4); 1910 * var actionBy = cc.jumpBy(2, 300, 0, 50, 4); 1911 */ 1912 cc.jumpBy = function (duration, position, y, height, jumps) { 1913 return new cc.JumpBy(duration, position, y, height, jumps); 1914 }; 1915 /** 1916 * Please use cc.jumpBy instead. <br /> 1917 * Moves a cc.Node object simulating a parabolic jump movement by modifying it's position attribute. <br /> 1918 * Relative to its movement. 1919 * @static 1920 * @deprecated since v3.0 please use cc.jumpBy instead. 1921 * @param {Number} duration 1922 * @param {cc.Point|Number} position 1923 * @param {Number} [y] 1924 * @param {Number} height 1925 * @param {Number} jumps 1926 * @return {cc.JumpBy} 1927 */ 1928 cc.JumpBy.create = cc.jumpBy; 1929 1930 /** 1931 * Moves a cc.Node object to a parabolic position simulating a jump movement by modifying it's position attribute. <br /> 1932 * Jump to the specified location. 1933 * @class 1934 * @extends cc.JumpBy 1935 * @param {Number} duration 1936 * @param {cc.Point|Number} position 1937 * @param {Number} [y] 1938 * @param {Number} height 1939 * @param {Number} jumps 1940 * @example 1941 * var actionTo = new cc.JumpTo(2, cc.p(300, 0), 50, 4); 1942 * var actionTo = new cc.JumpTo(2, 300, 0, 50, 4); 1943 */ 1944 cc.JumpTo = cc.JumpBy.extend(/** @lends cc.JumpTo# */{ 1945 _endPosition:null, 1946 1947 /** 1948 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 1949 * @param {Number} duration 1950 * @param {cc.Point|Number} position 1951 * @param {Number} [y] 1952 * @param {Number} height 1953 * @param {Number} jumps 1954 */ 1955 ctor:function (duration, position, y, height, jumps) { 1956 cc.JumpBy.prototype.ctor.call(this); 1957 this._endPosition = cc.p(0, 0); 1958 1959 height !== undefined && this.initWithDuration(duration, position, y, height, jumps); 1960 }, 1961 /** 1962 * Initializes the action. 1963 * @param {Number} duration 1964 * @param {cc.Point|Number} position 1965 * @param {Number} [y] 1966 * @param {Number} height 1967 * @param {Number} jumps 1968 * @return {Boolean} 1969 * @example 1970 * actionTo.initWithDuration(2, cc.p(300, 0), 50, 4); 1971 * actionTo.initWithDuration(2, 300, 0, 50, 4); 1972 */ 1973 initWithDuration:function (duration, position, y, height, jumps) { 1974 if (cc.JumpBy.prototype.initWithDuration.call(this, duration, position, y, height, jumps)) { 1975 if (jumps === undefined) { 1976 y = position.y; 1977 position = position.x; 1978 } 1979 this._endPosition.x = position; 1980 this._endPosition.y = y; 1981 return true; 1982 } 1983 return false; 1984 }, 1985 /** 1986 * Start the action with target. 1987 * @param {cc.Node} target 1988 */ 1989 startWithTarget:function (target) { 1990 cc.JumpBy.prototype.startWithTarget.call(this, target); 1991 this._delta.x = this._endPosition.x - this._startPosition.x; 1992 this._delta.y = this._endPosition.y - this._startPosition.y; 1993 }, 1994 1995 /** 1996 * returns a new clone of the action 1997 * @returns {cc.JumpTo} 1998 */ 1999 clone:function () { 2000 var action = new cc.JumpTo(); 2001 this._cloneDecoration(action); 2002 action.initWithDuration(this._duration, this._endPosition, this._height, this._jumps); 2003 return action; 2004 } 2005 }); 2006 2007 /** 2008 * Moves a cc.Node object to a parabolic position simulating a jump movement by modifying it's position attribute. <br /> 2009 * Jump to the specified location. 2010 * @function 2011 * @param {Number} duration 2012 * @param {cc.Point|Number} position 2013 * @param {Number} [y] 2014 * @param {Number} height 2015 * @param {Number} jumps 2016 * @return {cc.JumpTo} 2017 * @example 2018 * // example 2019 * var actionTo = cc.jumpTo(2, cc.p(300, 300), 50, 4); 2020 * var actionTo = cc.jumpTo(2, 300, 300, 50, 4); 2021 */ 2022 cc.jumpTo = function (duration, position, y, height, jumps) { 2023 return new cc.JumpTo(duration, position, y, height, jumps); 2024 }; 2025 /** 2026 * Please use cc.jumpTo instead. 2027 * Moves a cc.Node object to a parabolic position simulating a jump movement by modifying it's position attribute. <br /> 2028 * Jump to the specified location. 2029 * @static 2030 * @deprecated since v3.0 please use cc.jumpTo instead. 2031 * @param {Number} duration 2032 * @param {cc.Point|Number} position 2033 * @param {Number} [y] 2034 * @param {Number} height 2035 * @param {Number} jumps 2036 * @return {cc.JumpTo} 2037 */ 2038 cc.JumpTo.create = cc.jumpTo; 2039 2040 /** 2041 * @function 2042 * @param {Number} a 2043 * @param {Number} b 2044 * @param {Number} c 2045 * @param {Number} d 2046 * @param {Number} t 2047 * @return {Number} 2048 */ 2049 cc.bezierAt = function (a, b, c, d, t) { 2050 return (Math.pow(1 - t, 3) * a + 2051 3 * t * (Math.pow(1 - t, 2)) * b + 2052 3 * Math.pow(t, 2) * (1 - t) * c + 2053 Math.pow(t, 3) * d ); 2054 }; 2055 2056 /** An action that moves the target with a cubic Bezier curve by a certain distance. 2057 * Relative to its movement. 2058 * @class 2059 * @extends cc.ActionInterval 2060 * @param {Number} t time in seconds 2061 * @param {Array} c Array of points 2062 * @example 2063 * var bezier = [cc.p(0, windowSize.height / 2), cc.p(300, -windowSize.height / 2), cc.p(300, 100)]; 2064 * var bezierForward = new cc.BezierBy(3, bezier); 2065 */ 2066 cc.BezierBy = cc.ActionInterval.extend(/** @lends cc.BezierBy# */{ 2067 _config:null, 2068 _startPosition:null, 2069 _previousPosition:null, 2070 2071 /** 2072 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 2073 * @param {Number} t time in seconds 2074 * @param {Array} c Array of points 2075 */ 2076 ctor:function (t, c) { 2077 cc.ActionInterval.prototype.ctor.call(this); 2078 this._config = []; 2079 this._startPosition = cc.p(0, 0); 2080 this._previousPosition = cc.p(0, 0); 2081 2082 c && this.initWithDuration(t, c); 2083 }, 2084 2085 /** 2086 * Initializes the action. 2087 * @param {Number} t time in seconds 2088 * @param {Array} c Array of points 2089 * @return {Boolean} 2090 */ 2091 initWithDuration:function (t, c) { 2092 if (cc.ActionInterval.prototype.initWithDuration.call(this, t)) { 2093 this._config = c; 2094 return true; 2095 } 2096 return false; 2097 }, 2098 2099 /** 2100 * returns a new clone of the action 2101 * @returns {cc.BezierBy} 2102 */ 2103 clone:function () { 2104 var action = new cc.BezierBy(); 2105 this._cloneDecoration(action); 2106 var newConfigs = []; 2107 for (var i = 0; i < this._config.length; i++) { 2108 var selConf = this._config[i]; 2109 newConfigs.push(cc.p(selConf.x, selConf.y)); 2110 } 2111 action.initWithDuration(this._duration, newConfigs); 2112 return action; 2113 }, 2114 2115 /** 2116 * Start the action with target. 2117 * @param {cc.Node} target 2118 */ 2119 startWithTarget:function (target) { 2120 cc.ActionInterval.prototype.startWithTarget.call(this, target); 2121 var locPosX = target.getPositionX(); 2122 var locPosY = target.getPositionY(); 2123 this._previousPosition.x = locPosX; 2124 this._previousPosition.y = locPosY; 2125 this._startPosition.x = locPosX; 2126 this._startPosition.y = locPosY; 2127 }, 2128 2129 /** 2130 * Called once per frame. Time is the number of seconds of a frame interval. 2131 * @param {Number} dt 2132 */ 2133 update:function (dt) { 2134 dt = this._computeEaseTime(dt); 2135 if (this.target) { 2136 var locConfig = this._config; 2137 var xa = 0; 2138 var xb = locConfig[0].x; 2139 var xc = locConfig[1].x; 2140 var xd = locConfig[2].x; 2141 2142 var ya = 0; 2143 var yb = locConfig[0].y; 2144 var yc = locConfig[1].y; 2145 var yd = locConfig[2].y; 2146 2147 var x = cc.bezierAt(xa, xb, xc, xd, dt); 2148 var y = cc.bezierAt(ya, yb, yc, yd, dt); 2149 2150 var locStartPosition = this._startPosition; 2151 if (cc.ENABLE_STACKABLE_ACTIONS) { 2152 var targetX = this.target.getPositionX(); 2153 var targetY = this.target.getPositionY(); 2154 var locPreviousPosition = this._previousPosition; 2155 2156 locStartPosition.x = locStartPosition.x + targetX - locPreviousPosition.x; 2157 locStartPosition.y = locStartPosition.y + targetY - locPreviousPosition.y; 2158 x = x + locStartPosition.x; 2159 y = y + locStartPosition.y; 2160 locPreviousPosition.x = x; 2161 locPreviousPosition.y = y; 2162 this.target.setPosition(x, y); 2163 } else { 2164 this.target.setPosition(locStartPosition.x + x, locStartPosition.y + y); 2165 } 2166 } 2167 }, 2168 2169 /** 2170 * Returns a reversed action. 2171 * @return {cc.BezierBy} 2172 */ 2173 reverse:function () { 2174 var locConfig = this._config; 2175 var r = [ 2176 cc.pAdd(locConfig[1], cc.pNeg(locConfig[2])), 2177 cc.pAdd(locConfig[0], cc.pNeg(locConfig[2])), 2178 cc.pNeg(locConfig[2]) ]; 2179 var action = new cc.BezierBy(this._duration, r); 2180 this._cloneDecoration(action); 2181 this._reverseEaseList(action); 2182 return action; 2183 } 2184 }); 2185 2186 /** 2187 * An action that moves the target with a cubic Bezier curve by a certain distance. 2188 * Relative to its movement. 2189 * @function 2190 * @param {Number} t time in seconds 2191 * @param {Array} c Array of points 2192 * @return {cc.BezierBy} 2193 * @example 2194 * // example 2195 * var bezier = [cc.p(0, windowSize.height / 2), cc.p(300, -windowSize.height / 2), cc.p(300, 100)]; 2196 * var bezierForward = cc.bezierBy(3, bezier); 2197 */ 2198 cc.bezierBy = function (t, c) { 2199 return new cc.BezierBy(t, c); 2200 }; 2201 /** 2202 * Please use cc.bezierBy instead. 2203 * An action that moves the target with a cubic Bezier curve by a certain distance. 2204 * Relative to its movement. 2205 * @static 2206 * @deprecated since v3.0 please use cc.bezierBy instead. 2207 * @param {Number} t time in seconds 2208 * @param {Array} c Array of points 2209 * @return {cc.BezierBy} 2210 */ 2211 cc.BezierBy.create = cc.bezierBy; 2212 2213 2214 /** An action that moves the target with a cubic Bezier curve to a destination point. 2215 * @class 2216 * @extends cc.BezierBy 2217 * @param {Number} t 2218 * @param {Array} c array of points 2219 * @example 2220 * var bezier = [cc.p(0, windowSize.height / 2), cc.p(300, -windowSize.height / 2), cc.p(300, 100)]; 2221 * var bezierTo = new cc.BezierTo(2, bezier); 2222 */ 2223 cc.BezierTo = cc.BezierBy.extend(/** @lends cc.BezierTo# */{ 2224 _toConfig:null, 2225 2226 /** 2227 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 2228 * @param {Number} t 2229 * @param {Array} c array of points 2230 * var bezierTo = new cc.BezierTo(2, bezier); 2231 */ 2232 ctor:function (t, c) { 2233 cc.BezierBy.prototype.ctor.call(this); 2234 this._toConfig = []; 2235 c && this.initWithDuration(t, c); 2236 }, 2237 2238 /** 2239 * Initializes the action. 2240 * @param {Number} t time in seconds 2241 * @param {Array} c Array of points 2242 * @return {Boolean} 2243 */ 2244 initWithDuration:function (t, c) { 2245 if (cc.ActionInterval.prototype.initWithDuration.call(this, t)) { 2246 this._toConfig = c; 2247 return true; 2248 } 2249 return false; 2250 }, 2251 2252 /** 2253 * returns a new clone of the action 2254 * @returns {cc.BezierTo} 2255 */ 2256 clone:function () { 2257 var action = new cc.BezierTo(); 2258 this._cloneDecoration(action); 2259 action.initWithDuration(this._duration, this._toConfig); 2260 return action; 2261 }, 2262 2263 /** 2264 * Start the action with target. 2265 * @param {cc.Node} target 2266 */ 2267 startWithTarget:function (target) { 2268 cc.BezierBy.prototype.startWithTarget.call(this, target); 2269 var locStartPos = this._startPosition; 2270 var locToConfig = this._toConfig; 2271 var locConfig = this._config; 2272 2273 locConfig[0] = cc.pSub(locToConfig[0], locStartPos); 2274 locConfig[1] = cc.pSub(locToConfig[1], locStartPos); 2275 locConfig[2] = cc.pSub(locToConfig[2], locStartPos); 2276 } 2277 }); 2278 /** 2279 * An action that moves the target with a cubic Bezier curve to a destination point. 2280 * @function 2281 * @param {Number} t 2282 * @param {Array} c array of points 2283 * @return {cc.BezierTo} 2284 * @example 2285 * // example 2286 * var bezier = [cc.p(0, windowSize.height / 2), cc.p(300, -windowSize.height / 2), cc.p(300, 100)]; 2287 * var bezierTo = cc.bezierTo(2, bezier); 2288 */ 2289 cc.bezierTo = function (t, c) { 2290 return new cc.BezierTo(t, c); 2291 }; 2292 /** 2293 * Please use cc.bezierTo instead 2294 * @static 2295 * @deprecated since v3.0 please use cc.bezierTo instead. 2296 * @param {Number} t 2297 * @param {Array} c array of points 2298 * @return {cc.BezierTo} 2299 */ 2300 cc.BezierTo.create = cc.bezierTo; 2301 2302 2303 /** Scales a cc.Node object to a zoom factor by modifying it's scale attribute. 2304 * @warning This action doesn't support "reverse" 2305 * @class 2306 * @extends cc.ActionInterval 2307 * @param {Number} duration 2308 * @param {Number} sx scale parameter in X 2309 * @param {Number} [sy] scale parameter in Y, if Null equal to sx 2310 * @example 2311 * // It scales to 0.5 in both X and Y. 2312 * var actionTo = new cc.ScaleTo(2, 0.5); 2313 * 2314 * // It scales to 0.5 in x and 2 in Y 2315 * var actionTo = new cc.ScaleTo(2, 0.5, 2); 2316 */ 2317 cc.ScaleTo = cc.ActionInterval.extend(/** @lends cc.ScaleTo# */{ 2318 _scaleX:1, 2319 _scaleY:1, 2320 _startScaleX:1, 2321 _startScaleY:1, 2322 _endScaleX:0, 2323 _endScaleY:0, 2324 _deltaX:0, 2325 _deltaY:0, 2326 2327 /** 2328 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 2329 * @param {Number} duration 2330 * @param {Number} sx scale parameter in X 2331 * @param {Number} [sy] scale parameter in Y, if Null equal to sx 2332 */ 2333 ctor:function (duration, sx, sy) { 2334 cc.ActionInterval.prototype.ctor.call(this); 2335 sx !== undefined && this.initWithDuration(duration, sx, sy); 2336 }, 2337 2338 /** 2339 * Initializes the action. 2340 * @param {Number} duration 2341 * @param {Number} sx 2342 * @param {Number} [sy=] 2343 * @return {Boolean} 2344 */ 2345 initWithDuration:function (duration, sx, sy) { //function overload here 2346 if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) { 2347 this._endScaleX = sx; 2348 this._endScaleY = (sy != null) ? sy : sx; 2349 return true; 2350 } 2351 return false; 2352 }, 2353 2354 /** 2355 * returns a new clone of the action 2356 * @returns {cc.ScaleTo} 2357 */ 2358 clone:function () { 2359 var action = new cc.ScaleTo(); 2360 this._cloneDecoration(action); 2361 action.initWithDuration(this._duration, this._endScaleX, this._endScaleY); 2362 return action; 2363 }, 2364 2365 /** 2366 * Start the action with target. 2367 * @param {cc.Node} target 2368 */ 2369 startWithTarget:function (target) { 2370 cc.ActionInterval.prototype.startWithTarget.call(this, target); 2371 this._startScaleX = target.scaleX; 2372 this._startScaleY = target.scaleY; 2373 this._deltaX = this._endScaleX - this._startScaleX; 2374 this._deltaY = this._endScaleY - this._startScaleY; 2375 }, 2376 2377 /** 2378 * Called once per frame. Time is the number of seconds of a frame interval. 2379 * @param {Number} dt 2380 */ 2381 update:function (dt) { 2382 dt = this._computeEaseTime(dt); 2383 if (this.target) { 2384 this.target.scaleX = this._startScaleX + this._deltaX * dt; 2385 this.target.scaleY = this._startScaleY + this._deltaY * dt; 2386 } 2387 } 2388 }); 2389 /** 2390 * Scales a cc.Node object to a zoom factor by modifying it's scale attribute. 2391 * @function 2392 * @param {Number} duration 2393 * @param {Number} sx scale parameter in X 2394 * @param {Number} [sy] scale parameter in Y, if Null equal to sx 2395 * @return {cc.ScaleTo} 2396 * @example 2397 * // example 2398 * // It scales to 0.5 in both X and Y. 2399 * var actionTo = cc.scaleTo(2, 0.5); 2400 * 2401 * // It scales to 0.5 in x and 2 in Y 2402 * var actionTo = cc.scaleTo(2, 0.5, 2); 2403 */ 2404 cc.scaleTo = function (duration, sx, sy) { //function overload 2405 return new cc.ScaleTo(duration, sx, sy); 2406 }; 2407 /** 2408 * Please use cc.scaleTo instead. 2409 * Scales a cc.Node object to a zoom factor by modifying it's scale attribute. 2410 * @static 2411 * @deprecated since v3.0 please use cc.scaleTo instead. 2412 * @param {Number} duration 2413 * @param {Number} sx scale parameter in X 2414 * @param {Number} [sy] scale parameter in Y, if Null equal to sx 2415 * @return {cc.ScaleTo} 2416 */ 2417 cc.ScaleTo.create = cc.scaleTo; 2418 2419 2420 /** Scales a cc.Node object a zoom factor by modifying it's scale attribute. 2421 * Relative to its changes. 2422 * @class 2423 * @extends cc.ScaleTo 2424 */ 2425 cc.ScaleBy = cc.ScaleTo.extend(/** @lends cc.ScaleBy# */{ 2426 /** 2427 * Start the action with target. 2428 * @param {cc.Node} target 2429 */ 2430 startWithTarget:function (target) { 2431 cc.ScaleTo.prototype.startWithTarget.call(this, target); 2432 this._deltaX = this._startScaleX * this._endScaleX - this._startScaleX; 2433 this._deltaY = this._startScaleY * this._endScaleY - this._startScaleY; 2434 }, 2435 2436 /** 2437 * Returns a reversed action. 2438 * @return {cc.ScaleBy} 2439 */ 2440 reverse:function () { 2441 var action = new cc.ScaleBy(this._duration, 1 / this._endScaleX, 1 / this._endScaleY); 2442 this._cloneDecoration(action); 2443 this._reverseEaseList(action); 2444 return action; 2445 }, 2446 2447 /** 2448 * returns a new clone of the action 2449 * @returns {cc.ScaleBy} 2450 */ 2451 clone:function () { 2452 var action = new cc.ScaleBy(); 2453 this._cloneDecoration(action); 2454 action.initWithDuration(this._duration, this._endScaleX, this._endScaleY); 2455 return action; 2456 } 2457 }); 2458 /** 2459 * Scales a cc.Node object a zoom factor by modifying it's scale attribute. 2460 * Relative to its changes. 2461 * @function 2462 * @param {Number} duration duration in seconds 2463 * @param {Number} sx sx scale parameter in X 2464 * @param {Number|Null} [sy=] sy scale parameter in Y, if Null equal to sx 2465 * @return {cc.ScaleBy} 2466 * @example 2467 * // example without sy, it scales by 2 both in X and Y 2468 * var actionBy = cc.scaleBy(2, 2); 2469 * 2470 * //example with sy, it scales by 0.25 in X and 4.5 in Y 2471 * var actionBy2 = cc.scaleBy(2, 0.25, 4.5); 2472 */ 2473 cc.scaleBy = function (duration, sx, sy) { 2474 return new cc.ScaleBy(duration, sx, sy); 2475 }; 2476 /** 2477 * Please use cc.scaleBy instead. 2478 * Scales a cc.Node object a zoom factor by modifying it's scale attribute. 2479 * Relative to its changes. 2480 * @static 2481 * @deprecated since v3.0 please use cc.scaleBy() instead. 2482 * @param {Number} duration duration in seconds 2483 * @param {Number} sx sx scale parameter in X 2484 * @param {Number|Null} [sy=] sy scale parameter in Y, if Null equal to sx 2485 * @return {cc.ScaleBy} 2486 */ 2487 cc.ScaleBy.create = cc.scaleBy; 2488 2489 /** Blinks a cc.Node object by modifying it's visible attribute 2490 * @class 2491 * @extends cc.ActionInterval 2492 * @param {Number} duration duration in seconds 2493 * @param {Number} blinks blinks in times 2494 * @example 2495 * var action = new cc.Blink(2, 10); 2496 */ 2497 cc.Blink = cc.ActionInterval.extend(/** @lends cc.Blink# */{ 2498 _times:0, 2499 _originalState:false, 2500 2501 /** 2502 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 2503 * @param {Number} duration duration in seconds 2504 * @param {Number} blinks blinks in times 2505 */ 2506 ctor:function (duration, blinks) { 2507 cc.ActionInterval.prototype.ctor.call(this); 2508 blinks !== undefined && this.initWithDuration(duration, blinks); 2509 }, 2510 2511 /** 2512 * Initializes the action. 2513 * @param {Number} duration duration in seconds 2514 * @param {Number} blinks blinks in times 2515 * @return {Boolean} 2516 */ 2517 initWithDuration:function (duration, blinks) { 2518 if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) { 2519 this._times = blinks; 2520 return true; 2521 } 2522 return false; 2523 }, 2524 2525 /** 2526 * returns a new clone of the action 2527 * @returns {cc.Blink} 2528 */ 2529 clone:function () { 2530 var action = new cc.Blink(); 2531 this._cloneDecoration(action); 2532 action.initWithDuration(this._duration, this._times); 2533 return action; 2534 }, 2535 2536 /** 2537 * Called once per frame. Time is the number of seconds of a frame interval. 2538 * @param {Number} dt time in seconds 2539 */ 2540 update:function (dt) { 2541 dt = this._computeEaseTime(dt); 2542 if (this.target && !this.isDone()) { 2543 var slice = 1.0 / this._times; 2544 var m = dt % slice; 2545 this.target.visible = (m > (slice / 2)); 2546 } 2547 }, 2548 2549 /** 2550 * Start the action with target. 2551 * @param {cc.Node} target 2552 */ 2553 startWithTarget:function (target) { 2554 cc.ActionInterval.prototype.startWithTarget.call(this, target); 2555 this._originalState = target.visible; 2556 }, 2557 2558 /** 2559 * stop the action 2560 */ 2561 stop:function () { 2562 this.target.visible = this._originalState; 2563 cc.ActionInterval.prototype.stop.call(this); 2564 }, 2565 2566 /** 2567 * Returns a reversed action. 2568 * @return {cc.Blink} 2569 */ 2570 reverse:function () { 2571 var action = new cc.Blink(this._duration, this._times); 2572 this._cloneDecoration(action); 2573 this._reverseEaseList(action); 2574 return action; 2575 } 2576 }); 2577 /** 2578 * Blinks a cc.Node object by modifying it's visible attribute. 2579 * @function 2580 * @param {Number} duration duration in seconds 2581 * @param blinks blinks in times 2582 * @return {cc.Blink} 2583 * @example 2584 * // example 2585 * var action = cc.blink(2, 10); 2586 */ 2587 cc.blink = function (duration, blinks) { 2588 return new cc.Blink(duration, blinks); 2589 }; 2590 /** 2591 * Please use cc.blink instead. 2592 * Blinks a cc.Node object by modifying it's visible attribute. 2593 * @static 2594 * @deprecated since v3.0 please use cc.blink instead. 2595 * @param {Number} duration duration in seconds 2596 * @param blinks blinks in times 2597 * @return {cc.Blink} 2598 */ 2599 cc.Blink.create = cc.blink; 2600 2601 /** Fades an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from the current value to a custom one. 2602 * @warning This action doesn't support "reverse" 2603 * @class 2604 * @extends cc.ActionInterval 2605 * @param {Number} duration 2606 * @param {Number} opacity 0-255, 0 is transparent 2607 * @example 2608 * var action = new cc.FadeTo(1.0, 0); 2609 */ 2610 cc.FadeTo = cc.ActionInterval.extend(/** @lends cc.FadeTo# */{ 2611 _toOpacity:0, 2612 _fromOpacity:0, 2613 2614 /** 2615 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 2616 * @param {Number} duration 2617 * @param {Number} opacity 0-255, 0 is transparent 2618 */ 2619 ctor:function (duration, opacity) { 2620 cc.ActionInterval.prototype.ctor.call(this); 2621 opacity !== undefined && this.initWithDuration(duration, opacity); 2622 }, 2623 2624 /** 2625 * Initializes the action. 2626 * @param {Number} duration duration in seconds 2627 * @param {Number} opacity 2628 * @return {Boolean} 2629 */ 2630 initWithDuration:function (duration, opacity) { 2631 if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) { 2632 this._toOpacity = opacity; 2633 return true; 2634 } 2635 return false; 2636 }, 2637 2638 /** 2639 * returns a new clone of the action 2640 * @returns {cc.FadeTo} 2641 */ 2642 clone:function () { 2643 var action = new cc.FadeTo(); 2644 this._cloneDecoration(action); 2645 action.initWithDuration(this._duration, this._toOpacity); 2646 return action; 2647 }, 2648 2649 /** 2650 * Called once per frame. Time is the number of seconds of a frame interval. 2651 * @param {Number} time time in seconds 2652 */ 2653 update:function (time) { 2654 time = this._computeEaseTime(time); 2655 var fromOpacity = this._fromOpacity !== undefined ? this._fromOpacity : 255; 2656 this.target.opacity = fromOpacity + (this._toOpacity - fromOpacity) * time; 2657 }, 2658 2659 /** 2660 * Start this action with target. 2661 * @param {cc.Node} target 2662 */ 2663 startWithTarget:function (target) { 2664 cc.ActionInterval.prototype.startWithTarget.call(this, target); 2665 this._fromOpacity = target.opacity; 2666 } 2667 }); 2668 2669 /** 2670 * Fades an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from the current value to a custom one. 2671 * @function 2672 * @param {Number} duration 2673 * @param {Number} opacity 0-255, 0 is transparent 2674 * @return {cc.FadeTo} 2675 * @example 2676 * // example 2677 * var action = cc.fadeTo(1.0, 0); 2678 */ 2679 cc.fadeTo = function (duration, opacity) { 2680 return new cc.FadeTo(duration, opacity); 2681 }; 2682 /** 2683 * Please use cc.fadeTo instead. 2684 * Fades an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from the current value to a custom one. 2685 * @static 2686 * @deprecated since v3.0 please use cc.fadeTo instead. 2687 * @param {Number} duration 2688 * @param {Number} opacity 0-255, 0 is transparent 2689 * @return {cc.FadeTo} 2690 */ 2691 cc.FadeTo.create = cc.fadeTo; 2692 2693 /** Fades In an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from 0 to 255.<br/> 2694 * The "reverse" of this action is FadeOut 2695 * @class 2696 * @extends cc.FadeTo 2697 * @param {Number} duration duration in seconds 2698 */ 2699 cc.FadeIn = cc.FadeTo.extend(/** @lends cc.FadeIn# */{ 2700 _reverseAction: null, 2701 2702 /** 2703 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 2704 * @param {Number} duration duration in seconds 2705 */ 2706 ctor:function (duration) { 2707 cc.FadeTo.prototype.ctor.call(this); 2708 if (duration == null) 2709 duration = 0; 2710 this.initWithDuration(duration, 255); 2711 }, 2712 2713 /** 2714 * Returns a reversed action. 2715 * @return {cc.FadeOut} 2716 */ 2717 reverse:function () { 2718 var action = new cc.FadeOut(); 2719 action.initWithDuration(this._duration, 0); 2720 this._cloneDecoration(action); 2721 this._reverseEaseList(action); 2722 return action; 2723 }, 2724 2725 /** 2726 * returns a new clone of the action 2727 * @returns {cc.FadeIn} 2728 */ 2729 clone:function () { 2730 var action = new cc.FadeIn(); 2731 this._cloneDecoration(action); 2732 action.initWithDuration(this._duration, this._toOpacity); 2733 return action; 2734 }, 2735 2736 /** 2737 * Start the action with target. 2738 * @param {cc.Node} target 2739 */ 2740 startWithTarget:function (target) { 2741 if(this._reverseAction) 2742 this._toOpacity = this._reverseAction._fromOpacity; 2743 cc.FadeTo.prototype.startWithTarget.call(this, target); 2744 } 2745 }); 2746 2747 /** 2748 * Fades In an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from 0 to 255. 2749 * @function 2750 * @param {Number} duration duration in seconds 2751 * @return {cc.FadeIn} 2752 * @example 2753 * //example 2754 * var action = cc.fadeIn(1.0); 2755 */ 2756 cc.fadeIn = function (duration) { 2757 return new cc.FadeIn(duration); 2758 }; 2759 /** 2760 * Please use cc.fadeIn instead. 2761 * Fades In an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from 0 to 255. 2762 * @static 2763 * @deprecated since v3.0 please use cc.fadeIn() instead. 2764 * @param {Number} duration duration in seconds 2765 * @return {cc.FadeIn} 2766 */ 2767 cc.FadeIn.create = cc.fadeIn; 2768 2769 2770 /** Fades Out an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from 255 to 0. 2771 * The "reverse" of this action is FadeIn 2772 * @class 2773 * @extends cc.FadeTo 2774 * @param {Number} duration duration in seconds 2775 */ 2776 cc.FadeOut = cc.FadeTo.extend(/** @lends cc.FadeOut# */{ 2777 2778 /** 2779 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 2780 * @param {Number} duration duration in seconds 2781 */ 2782 ctor:function (duration) { 2783 cc.FadeTo.prototype.ctor.call(this); 2784 if (duration == null) 2785 duration = 0; 2786 this.initWithDuration(duration, 0); 2787 }, 2788 2789 /** 2790 * Returns a reversed action. 2791 * @return {cc.FadeIn} 2792 */ 2793 reverse:function () { 2794 var action = new cc.FadeIn(); 2795 action._reverseAction = this; 2796 action.initWithDuration(this._duration, 255); 2797 this._cloneDecoration(action); 2798 this._reverseEaseList(action); 2799 return action; 2800 }, 2801 2802 /** 2803 * returns a new clone of the action 2804 * @returns {cc.FadeOut} 2805 */ 2806 clone:function () { 2807 var action = new cc.FadeOut(); 2808 this._cloneDecoration(action); 2809 action.initWithDuration(this._duration, this._toOpacity); 2810 return action; 2811 } 2812 }); 2813 2814 /** 2815 * Fades Out an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from 255 to 0. 2816 * @function 2817 * @param {Number} d duration in seconds 2818 * @return {cc.FadeOut} 2819 * @example 2820 * // example 2821 * var action = cc.fadeOut(1.0); 2822 */ 2823 cc.fadeOut = function (d) { 2824 return new cc.FadeOut(d); 2825 }; 2826 /** 2827 * Please use cc.fadeOut instead. 2828 * Fades Out an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from 255 to 0. 2829 * @static 2830 * @deprecated since v3.0 please use cc.fadeOut instead. 2831 * @param {Number} d duration in seconds 2832 * @return {cc.FadeOut} 2833 */ 2834 cc.FadeOut.create = cc.fadeOut; 2835 2836 /** Tints a cc.Node that implements the cc.NodeRGB protocol from current tint to a custom one. 2837 * @warning This action doesn't support "reverse" 2838 * @class 2839 * @extends cc.ActionInterval 2840 * @param {Number} duration 2841 * @param {Number} red 0-255 2842 * @param {Number} green 0-255 2843 * @param {Number} blue 0-255 2844 * @example 2845 * var action = new cc.TintTo(2, 255, 0, 255); 2846 */ 2847 cc.TintTo = cc.ActionInterval.extend(/** @lends cc.TintTo# */{ 2848 _to:null, 2849 _from:null, 2850 2851 /** 2852 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 2853 * @param {Number} duration 2854 * @param {Number} red 0-255 2855 * @param {Number} green 0-255 2856 * @param {Number} blue 0-255 2857 */ 2858 ctor:function (duration, red, green, blue) { 2859 cc.ActionInterval.prototype.ctor.call(this); 2860 this._to = cc.color(0, 0, 0); 2861 this._from = cc.color(0, 0, 0); 2862 2863 blue !== undefined && this.initWithDuration(duration, red, green, blue); 2864 }, 2865 2866 /** 2867 * Initializes the action. 2868 * @param {Number} duration 2869 * @param {Number} red 0-255 2870 * @param {Number} green 0-255 2871 * @param {Number} blue 0-255 2872 * @return {Boolean} 2873 */ 2874 initWithDuration:function (duration, red, green, blue) { 2875 if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) { 2876 this._to = cc.color(red, green, blue); 2877 return true; 2878 } 2879 return false; 2880 }, 2881 2882 /** 2883 * returns a new clone of the action 2884 * @returns {cc.TintTo} 2885 */ 2886 clone:function () { 2887 var action = new cc.TintTo(); 2888 this._cloneDecoration(action); 2889 var locTo = this._to; 2890 action.initWithDuration(this._duration, locTo.r, locTo.g, locTo.b); 2891 return action; 2892 }, 2893 2894 /** 2895 * Start the action with target. 2896 * @param {cc.Node} target 2897 */ 2898 startWithTarget:function (target) { 2899 cc.ActionInterval.prototype.startWithTarget.call(this, target); 2900 2901 this._from = this.target.color; 2902 }, 2903 2904 /** 2905 * Called once per frame. Time is the number of seconds of a frame interval. 2906 * @param {Number} dt time in seconds 2907 */ 2908 update:function (dt) { 2909 dt = this._computeEaseTime(dt); 2910 var locFrom = this._from, locTo = this._to; 2911 if (locFrom) { 2912 this.target.setColor( 2913 cc.color( 2914 locFrom.r + (locTo.r - locFrom.r) * dt, 2915 locFrom.g + (locTo.g - locFrom.g) * dt, 2916 locFrom.b + (locTo.b - locFrom.b) * dt) 2917 ); 2918 } 2919 } 2920 }); 2921 2922 /** 2923 * Tints a cc.Node that implements the cc.NodeRGB protocol from current tint to a custom one. 2924 * @function 2925 * @param {Number} duration 2926 * @param {Number} red 0-255 2927 * @param {Number} green 0-255 2928 * @param {Number} blue 0-255 2929 * @return {cc.TintTo} 2930 * @example 2931 * // example 2932 * var action = cc.tintTo(2, 255, 0, 255); 2933 */ 2934 cc.tintTo = function (duration, red, green, blue) { 2935 return new cc.TintTo(duration, red, green, blue); 2936 }; 2937 /** 2938 * Please use cc.tintTo instead. 2939 * Tints a cc.Node that implements the cc.NodeRGB protocol from current tint to a custom one. 2940 * @static 2941 * @deprecated since v3.0 please use cc.tintTo instead. 2942 * @param {Number} duration 2943 * @param {Number} red 0-255 2944 * @param {Number} green 0-255 2945 * @param {Number} blue 0-255 2946 * @return {cc.TintTo} 2947 */ 2948 cc.TintTo.create = cc.tintTo; 2949 2950 2951 /** Tints a cc.Node that implements the cc.NodeRGB protocol from current tint to a custom one. 2952 * Relative to their own color change. 2953 * @class 2954 * @extends cc.ActionInterval 2955 * @param {Number} duration duration in seconds 2956 * @param {Number} deltaRed 2957 * @param {Number} deltaGreen 2958 * @param {Number} deltaBlue 2959 * @example 2960 * var action = new cc.TintBy(2, -127, -255, -127); 2961 */ 2962 cc.TintBy = cc.ActionInterval.extend(/** @lends cc.TintBy# */{ 2963 _deltaR:0, 2964 _deltaG:0, 2965 _deltaB:0, 2966 2967 _fromR:0, 2968 _fromG:0, 2969 _fromB:0, 2970 2971 /** 2972 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 2973 * @param {Number} duration duration in seconds 2974 * @param {Number} deltaRed 2975 * @param {Number} deltaGreen 2976 * @param {Number} deltaBlue 2977 */ 2978 ctor:function (duration, deltaRed, deltaGreen, deltaBlue) { 2979 cc.ActionInterval.prototype.ctor.call(this); 2980 deltaBlue !== undefined && this.initWithDuration(duration, deltaRed, deltaGreen, deltaBlue); 2981 }, 2982 2983 /** 2984 * Initializes the action. 2985 * @param {Number} duration 2986 * @param {Number} deltaRed 0-255 2987 * @param {Number} deltaGreen 0-255 2988 * @param {Number} deltaBlue 0-255 2989 * @return {Boolean} 2990 */ 2991 initWithDuration:function (duration, deltaRed, deltaGreen, deltaBlue) { 2992 if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) { 2993 this._deltaR = deltaRed; 2994 this._deltaG = deltaGreen; 2995 this._deltaB = deltaBlue; 2996 return true; 2997 } 2998 return false; 2999 }, 3000 3001 /** 3002 * returns a new clone of the action 3003 * @returns {cc.TintBy} 3004 */ 3005 clone:function () { 3006 var action = new cc.TintBy(); 3007 this._cloneDecoration(action); 3008 action.initWithDuration(this._duration, this._deltaR, this._deltaG, this._deltaB); 3009 return action; 3010 }, 3011 3012 /** 3013 * Start the action with target. 3014 * @param {cc.Node} target 3015 */ 3016 startWithTarget:function (target) { 3017 cc.ActionInterval.prototype.startWithTarget.call(this, target); 3018 3019 var color = target.color; 3020 this._fromR = color.r; 3021 this._fromG = color.g; 3022 this._fromB = color.b; 3023 3024 }, 3025 3026 /** 3027 * Called once per frame. Time is the number of seconds of a frame interval. 3028 * @param {Number} dt time in seconds 3029 */ 3030 update:function (dt) { 3031 dt = this._computeEaseTime(dt); 3032 3033 this.target.color = cc.color(this._fromR + this._deltaR * dt, 3034 this._fromG + this._deltaG * dt, 3035 this._fromB + this._deltaB * dt); 3036 3037 }, 3038 3039 /** 3040 * Returns a reversed action. 3041 * @return {cc.TintBy} 3042 */ 3043 reverse:function () { 3044 var action = new cc.TintBy(this._duration, -this._deltaR, -this._deltaG, -this._deltaB); 3045 this._cloneDecoration(action); 3046 this._reverseEaseList(action); 3047 return action; 3048 } 3049 }); 3050 3051 /** 3052 * Tints a cc.Node that implements the cc.NodeRGB protocol from current tint to a custom one. 3053 * Relative to their own color change. 3054 * @function 3055 * @param {Number} duration duration in seconds 3056 * @param {Number} deltaRed 3057 * @param {Number} deltaGreen 3058 * @param {Number} deltaBlue 3059 * @return {cc.TintBy} 3060 * @example 3061 * // example 3062 * var action = cc.tintBy(2, -127, -255, -127); 3063 */ 3064 cc.tintBy = function (duration, deltaRed, deltaGreen, deltaBlue) { 3065 return new cc.TintBy(duration, deltaRed, deltaGreen, deltaBlue); 3066 }; 3067 /** 3068 * Please use cc.tintBy instead. 3069 * Tints a cc.Node that implements the cc.NodeRGB protocol from current tint to a custom one. 3070 * Relative to their own color change. 3071 * @static 3072 * @deprecated since v3.0 please use cc.tintBy instead. 3073 * @param {Number} duration duration in seconds 3074 * @param {Number} deltaRed 3075 * @param {Number} deltaGreen 3076 * @param {Number} deltaBlue 3077 * @return {cc.TintBy} 3078 */ 3079 cc.TintBy.create = cc.tintBy; 3080 3081 /** Delays the action a certain amount of seconds 3082 * @class 3083 * @extends cc.ActionInterval 3084 */ 3085 cc.DelayTime = cc.ActionInterval.extend(/** @lends cc.DelayTime# */{ 3086 /** 3087 * Called once per frame. Time is the number of seconds of a frame interval. 3088 * Will be overwrite. 3089 * @param {Number} dt time in seconds 3090 */ 3091 update:function (dt) {}, 3092 3093 /** 3094 * Returns a reversed action. 3095 * @return {cc.DelayTime} 3096 */ 3097 reverse:function () { 3098 var action = new cc.DelayTime(this._duration); 3099 this._cloneDecoration(action); 3100 this._reverseEaseList(action); 3101 return action; 3102 }, 3103 3104 /** 3105 * returns a new clone of the action 3106 * @returns {cc.DelayTime} 3107 */ 3108 clone:function () { 3109 var action = new cc.DelayTime(); 3110 this._cloneDecoration(action); 3111 action.initWithDuration(this._duration); 3112 return action; 3113 } 3114 }); 3115 3116 /** 3117 * Delays the action a certain amount of seconds 3118 * @function 3119 * @param {Number} d duration in seconds 3120 * @return {cc.DelayTime} 3121 * @example 3122 * // example 3123 * var delay = cc.delayTime(1); 3124 */ 3125 cc.delayTime = function (d) { 3126 return new cc.DelayTime(d); 3127 }; 3128 /** 3129 * Please use cc.delayTime instead. 3130 * Delays the action a certain amount of seconds 3131 * @static 3132 * @deprecated since v3.0 please use cc.delaTime instead. 3133 * @param {Number} d duration in seconds 3134 * @return {cc.DelayTime} 3135 */ 3136 cc.DelayTime.create = cc.delayTime; 3137 3138 /** 3139 * <p> 3140 * Executes an action in reverse order, from time=duration to time=0 <br/> 3141 * @warning Use this action carefully. This action is not sequenceable. <br/> 3142 * Use it as the default "reversed" method of your own actions, but using it outside the "reversed" <br/> 3143 * scope is not recommended. 3144 * </p> 3145 * @class 3146 * @extends cc.ActionInterval 3147 * @param {cc.FiniteTimeAction} action 3148 * @example 3149 * var reverse = new cc.ReverseTime(this); 3150 */ 3151 cc.ReverseTime = cc.ActionInterval.extend(/** @lends cc.ReverseTime# */{ 3152 _other:null, 3153 3154 /** 3155 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 3156 * @param {cc.FiniteTimeAction} action 3157 */ 3158 ctor:function (action) { 3159 cc.ActionInterval.prototype.ctor.call(this); 3160 this._other = null; 3161 3162 action && this.initWithAction(action); 3163 }, 3164 3165 /** 3166 * @param {cc.FiniteTimeAction} action 3167 * @return {Boolean} 3168 */ 3169 initWithAction:function (action) { 3170 if(!action) 3171 throw new Error("cc.ReverseTime.initWithAction(): action must be non null"); 3172 if(action === this._other) 3173 throw new Error("cc.ReverseTime.initWithAction(): the action was already passed in."); 3174 3175 if (cc.ActionInterval.prototype.initWithDuration.call(this, action._duration)) { 3176 // Don't leak if action is reused 3177 this._other = action; 3178 return true; 3179 } 3180 return false; 3181 }, 3182 3183 /** 3184 * returns a new clone of the action 3185 * @returns {cc.ReverseTime} 3186 */ 3187 clone:function () { 3188 var action = new cc.ReverseTime(); 3189 this._cloneDecoration(action); 3190 action.initWithAction(this._other.clone()); 3191 return action; 3192 }, 3193 3194 /** 3195 * Start the action with target. 3196 * @param {cc.Node} target 3197 */ 3198 startWithTarget:function (target) { 3199 cc.ActionInterval.prototype.startWithTarget.call(this, target); 3200 this._other.startWithTarget(target); 3201 }, 3202 3203 /** 3204 * Called once per frame. Time is the number of seconds of a frame interval. 3205 * @param {Number} dt time in seconds 3206 */ 3207 update:function (dt) { 3208 dt = this._computeEaseTime(dt); 3209 if (this._other) 3210 this._other.update(1 - dt); 3211 }, 3212 3213 /** 3214 * Returns a reversed action. 3215 * @return {cc.ActionInterval} 3216 */ 3217 reverse:function () { 3218 return this._other.clone(); 3219 }, 3220 3221 /** 3222 * Stop the action 3223 */ 3224 stop:function () { 3225 this._other.stop(); 3226 cc.Action.prototype.stop.call(this); 3227 } 3228 }); 3229 3230 /** 3231 * Executes an action in reverse order, from time=duration to time=0. 3232 * @function 3233 * @param {cc.FiniteTimeAction} action 3234 * @return {cc.ReverseTime} 3235 * @example 3236 * // example 3237 * var reverse = cc.reverseTime(this); 3238 */ 3239 cc.reverseTime = function (action) { 3240 return new cc.ReverseTime(action); 3241 }; 3242 /** 3243 * Please use cc.reverseTime instead. 3244 * Executes an action in reverse order, from time=duration to time=0. 3245 * @static 3246 * @deprecated since v3.0 please use cc.reverseTime instead. 3247 * @param {cc.FiniteTimeAction} action 3248 * @return {cc.ReverseTime} 3249 */ 3250 cc.ReverseTime.create = cc.reverseTime; 3251 3252 3253 /** Animates a sprite given the name of an Animation 3254 * @class 3255 * @extends cc.ActionInterval 3256 * @param {cc.Animation} animation 3257 * @example 3258 * // create the animation with animation 3259 * var anim = new cc.Animate(dance_grey); 3260 */ 3261 cc.Animate = cc.ActionInterval.extend(/** @lends cc.Animate# */{ 3262 _animation:null, 3263 _nextFrame:0, 3264 _origFrame:null, 3265 _executedLoops:0, 3266 _splitTimes: null, 3267 _currFrameIndex:0, 3268 3269 /** 3270 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br /> 3271 * create the animate with animation. 3272 * @param {cc.Animation} animation 3273 */ 3274 ctor:function (animation) { 3275 cc.ActionInterval.prototype.ctor.call(this); 3276 this._splitTimes = []; 3277 3278 animation && this.initWithAnimation(animation); 3279 }, 3280 3281 /** 3282 * @return {cc.Animation} 3283 */ 3284 getAnimation:function () { 3285 return this._animation; 3286 }, 3287 3288 /** 3289 * @param {cc.Animation} animation 3290 */ 3291 setAnimation:function (animation) { 3292 this._animation = animation; 3293 }, 3294 3295 /** 3296 * Gets the index of sprite frame currently displayed. 3297 * @return {Number} 3298 */ 3299 getCurrentFrameIndex: function () { 3300 return this._currFrameIndex; 3301 }, 3302 3303 /** 3304 * @param {cc.Animation} animation 3305 * @return {Boolean} 3306 */ 3307 initWithAnimation:function (animation) { 3308 if(!animation) 3309 throw new Error("cc.Animate.initWithAnimation(): animation must be non-NULL"); 3310 var singleDuration = animation.getDuration(); 3311 if (this.initWithDuration(singleDuration * animation.getLoops())) { 3312 this._nextFrame = 0; 3313 this.setAnimation(animation); 3314 3315 this._origFrame = null; 3316 this._executedLoops = 0; 3317 var locTimes = this._splitTimes; 3318 locTimes.length = 0; 3319 3320 var accumUnitsOfTime = 0; 3321 var newUnitOfTimeValue = singleDuration / animation.getTotalDelayUnits(); 3322 3323 var frames = animation.getFrames(); 3324 cc.arrayVerifyType(frames, cc.AnimationFrame); 3325 3326 for (var i = 0; i < frames.length; i++) { 3327 var frame = frames[i]; 3328 var value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration; 3329 accumUnitsOfTime += frame.getDelayUnits(); 3330 locTimes.push(value); 3331 } 3332 return true; 3333 } 3334 return false; 3335 }, 3336 3337 /** 3338 * returns a new clone of the action 3339 * @returns {cc.Animate} 3340 */ 3341 clone:function () { 3342 var action = new cc.Animate(); 3343 this._cloneDecoration(action); 3344 action.initWithAnimation(this._animation.clone()); 3345 return action; 3346 }, 3347 3348 /** 3349 * Start the action with target. 3350 * @param {cc.Sprite} target 3351 */ 3352 startWithTarget:function (target) { 3353 cc.ActionInterval.prototype.startWithTarget.call(this, target); 3354 if (this._animation.getRestoreOriginalFrame()) 3355 this._origFrame = target.displayFrame(); 3356 this._nextFrame = 0; 3357 this._executedLoops = 0; 3358 }, 3359 3360 /** 3361 * Called once per frame. Time is the number of seconds of a frame interval. 3362 * @param {Number} dt 3363 */ 3364 update:function (dt) { 3365 dt = this._computeEaseTime(dt); 3366 // if t==1, ignore. Animation should finish with t==1 3367 if (dt < 1.0) { 3368 dt *= this._animation.getLoops(); 3369 3370 // new loop? If so, reset frame counter 3371 var loopNumber = 0 | dt; 3372 if (loopNumber > this._executedLoops) { 3373 this._nextFrame = 0; 3374 this._executedLoops++; 3375 } 3376 3377 // new t for animations 3378 dt = dt % 1.0; 3379 } 3380 3381 var frames = this._animation.getFrames(); 3382 var numberOfFrames = frames.length, locSplitTimes = this._splitTimes; 3383 for (var i = this._nextFrame; i < numberOfFrames; i++) { 3384 if (locSplitTimes[i] <= dt) { 3385 _currFrameIndex = i; 3386 this.target.setSpriteFrame(frames[_currFrameIndex].getSpriteFrame()); 3387 this._nextFrame = i + 1; 3388 } else { 3389 // Issue 1438. Could be more than one frame per tick, due to low frame rate or frame delta < 1/FPS 3390 break; 3391 } 3392 } 3393 }, 3394 3395 /** 3396 * Returns a reversed action. 3397 * @return {cc.Animate} 3398 */ 3399 reverse:function () { 3400 var locAnimation = this._animation; 3401 var oldArray = locAnimation.getFrames(); 3402 var newArray = []; 3403 cc.arrayVerifyType(oldArray, cc.AnimationFrame); 3404 if (oldArray.length > 0) { 3405 for (var i = oldArray.length - 1; i >= 0; i--) { 3406 var element = oldArray[i]; 3407 if (!element) 3408 break; 3409 newArray.push(element.clone()); 3410 } 3411 } 3412 var newAnim = new cc.Animation(newArray, locAnimation.getDelayPerUnit(), locAnimation.getLoops()); 3413 newAnim.setRestoreOriginalFrame(locAnimation.getRestoreOriginalFrame()); 3414 var action = new cc.Animate(newAnim); 3415 this._cloneDecoration(action); 3416 this._reverseEaseList(action); 3417 3418 return action; 3419 }, 3420 3421 /** 3422 * stop the action 3423 */ 3424 stop:function () { 3425 if (this._animation.getRestoreOriginalFrame() && this.target) 3426 this.target.setSpriteFrame(this._origFrame); 3427 cc.Action.prototype.stop.call(this); 3428 } 3429 }); 3430 3431 /** 3432 * create the animate with animation 3433 * @function 3434 * @param {cc.Animation} animation 3435 * @return {cc.Animate} 3436 * @example 3437 * // example 3438 * // create the animation with animation 3439 * var anim = cc.animate(dance_grey); 3440 */ 3441 cc.animate = function (animation) { 3442 return new cc.Animate(animation); 3443 }; 3444 /** 3445 * Please use cc.animate instead 3446 * create the animate with animation 3447 * @static 3448 * @deprecated since v3.0 please use cc.animate instead. 3449 * @param {cc.Animation} animation 3450 * @return {cc.Animate} 3451 */ 3452 cc.Animate.create = cc.animate; 3453 3454 /** 3455 * <p> 3456 * Overrides the target of an action so that it always runs on the target<br/> 3457 * specified at action creation rather than the one specified by runAction. 3458 * </p> 3459 * @class 3460 * @extends cc.ActionInterval 3461 * @param {cc.Node} target 3462 * @param {cc.FiniteTimeAction} action 3463 */ 3464 cc.TargetedAction = cc.ActionInterval.extend(/** @lends cc.TargetedAction# */{ 3465 _action:null, 3466 _forcedTarget:null, 3467 3468 /** 3469 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br /> 3470 * Create an action with the specified action and forced target. 3471 * @param {cc.Node} target 3472 * @param {cc.FiniteTimeAction} action 3473 */ 3474 ctor: function (target, action) { 3475 cc.ActionInterval.prototype.ctor.call(this); 3476 action && this.initWithTarget(target, action); 3477 }, 3478 3479 /** 3480 * Init an action with the specified action and forced target 3481 * @param {cc.Node} target 3482 * @param {cc.FiniteTimeAction} action 3483 * @return {Boolean} 3484 */ 3485 initWithTarget:function (target, action) { 3486 if (this.initWithDuration(action._duration)) { 3487 this._forcedTarget = target; 3488 this._action = action; 3489 return true; 3490 } 3491 return false; 3492 }, 3493 3494 /** 3495 * returns a new clone of the action 3496 * @returns {cc.TargetedAction} 3497 */ 3498 clone:function () { 3499 var action = new cc.TargetedAction(); 3500 this._cloneDecoration(action); 3501 action.initWithTarget(this._forcedTarget, this._action.clone()); 3502 return action; 3503 }, 3504 3505 /** 3506 * Start the action with target. 3507 * @param {cc.Node} target 3508 */ 3509 startWithTarget:function (target) { 3510 cc.ActionInterval.prototype.startWithTarget.call(this, target); 3511 this._action.startWithTarget(this._forcedTarget); 3512 }, 3513 3514 /** 3515 * stop the action 3516 */ 3517 stop:function () { 3518 this._action.stop(); 3519 }, 3520 3521 /** 3522 * Called once per frame. Time is the number of seconds of a frame interval. 3523 * @param {Number} dt 3524 */ 3525 update:function (dt) { 3526 dt = this._computeEaseTime(dt); 3527 this._action.update(dt); 3528 }, 3529 3530 /** 3531 * return the target that the action will be forced to run with 3532 * @return {cc.Node} 3533 */ 3534 getForcedTarget:function () { 3535 return this._forcedTarget; 3536 }, 3537 3538 /** 3539 * set the target that the action will be forced to run with 3540 * @param {cc.Node} forcedTarget 3541 */ 3542 setForcedTarget:function (forcedTarget) { 3543 if (this._forcedTarget !== forcedTarget) 3544 this._forcedTarget = forcedTarget; 3545 } 3546 }); 3547 3548 /** 3549 * Create an action with the specified action and forced target 3550 * @function 3551 * @param {cc.Node} target 3552 * @param {cc.FiniteTimeAction} action 3553 * @return {cc.TargetedAction} 3554 */ 3555 cc.targetedAction = function (target, action) { 3556 return new cc.TargetedAction(target, action); 3557 }; 3558 /** 3559 * Please use cc.targetedAction instead 3560 * Create an action with the specified action and forced target 3561 * @static 3562 * @deprecated since v3.0 please use cc.targetedAction instead. 3563 * @param {cc.Node} target 3564 * @param {cc.FiniteTimeAction} action 3565 * @return {cc.TargetedAction} 3566 */ 3567 cc.TargetedAction.create = cc.targetedAction; 3568