CCActionEase.js 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124
  1. /****************************************************************************
  2. Copyright (c) 2010-2012 cocos2d-x.org
  3. Copyright (c) 2008-2010 Ricardo Quesada
  4. Copyright (c) 2011 Zynga Inc.
  5. http://www.cocos2d-x.org
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. ****************************************************************************/
  22. /**
  23. * Base class for Easing actions
  24. * @class
  25. * @extends cc.ActionInterval
  26. */
  27. cc.ActionEase = cc.ActionInterval.extend(/** @lends cc.ActionEase# */{
  28. _inner:null,
  29. ctor:function(){
  30. cc.ActionInterval.prototype.ctor.call(this);
  31. this._inner = null;
  32. },
  33. /** initializes the action
  34. * @param {cc.ActionInterval} action
  35. * @return {Boolean}
  36. */
  37. initWithAction:function (action) {
  38. if(!action)
  39. throw "cc.ActionEase.initWithAction(): action must be non nil";
  40. if (this.initWithDuration(action.getDuration())) {
  41. this._inner = action;
  42. return true;
  43. }
  44. return false;
  45. },
  46. clone:function(){
  47. var action = new cc.ActionEase();
  48. action.initWithAction(this._inner.clone());
  49. return action;
  50. },
  51. /**
  52. * @param {cc.Node} target
  53. */
  54. startWithTarget:function (target) {
  55. cc.ActionInterval.prototype.startWithTarget.call(this, target);
  56. this._inner.startWithTarget(this._target);
  57. },
  58. /**
  59. * Stop the action.
  60. */
  61. stop:function () {
  62. this._inner.stop();
  63. cc.ActionInterval.prototype.stop.call(this);
  64. },
  65. /**
  66. * @param {Number} time1
  67. */
  68. update:function (time1) {
  69. this._inner.update(time1);
  70. },
  71. /**
  72. * @return {cc.ActionInterval}
  73. */
  74. reverse:function () {
  75. return cc.ActionEase.create(this._inner.reverse());
  76. },
  77. getInnerAction:function(){
  78. return this._inner;
  79. }
  80. });
  81. /** creates the action of ActionEase
  82. * @param {cc.ActionInterval} action
  83. * @return {cc.ActionEase}
  84. * @example
  85. * // example
  86. * var moveEase = cc.ActionEase.create(action);
  87. */
  88. cc.ActionEase.create = function (action) {
  89. var ret = new cc.ActionEase();
  90. if (ret)
  91. ret.initWithAction(action);
  92. return ret;
  93. };
  94. /**
  95. * Base class for Easing actions with rate parameters
  96. * @class
  97. * @extends cc.ActionEase
  98. */
  99. cc.EaseRateAction = cc.ActionEase.extend(/** @lends cc.EaseRateAction# */{
  100. _rate:0,
  101. ctor:function(){
  102. cc.ActionEase.prototype.ctor.call(this);
  103. this._rate = 0;
  104. },
  105. /** set rate value for the actions
  106. * @param {Number} rate
  107. */
  108. setRate:function (rate) {
  109. this._rate = rate;
  110. },
  111. /** get rate value for the actions
  112. * @return {Number}
  113. */
  114. getRate:function () {
  115. return this._rate;
  116. },
  117. /**
  118. * Initializes the action with the inner action and the rate parameter
  119. * @param {cc.ActionInterval} action
  120. * @param {Number} rate
  121. * @return {Boolean}
  122. */
  123. initWithAction:function (action, rate) {
  124. if (cc.ActionEase.prototype.initWithAction.call(this, action)) {
  125. this._rate = rate;
  126. return true;
  127. }
  128. return false;
  129. },
  130. clone:function(){
  131. var action = new cc.EaseRateAction();
  132. action.initWithAction(this._inner.clone(), this._rate);
  133. return action;
  134. },
  135. /**
  136. * @return {cc.ActionInterval}
  137. */
  138. reverse:function () {
  139. return cc.EaseRateAction.create(this._inner.reverse(), 1 / this._rate);
  140. }
  141. });
  142. /** Creates the action with the inner action and the rate parameter
  143. * @param {cc.ActionInterval} action
  144. * @param {Number} rate
  145. * @return {cc.EaseRateAction}
  146. * @example
  147. * // example
  148. * var moveEaseRateAction = cc.EaseRateAction.create(action, 3.0);
  149. */
  150. cc.EaseRateAction.create = function (action, rate) {
  151. var ret = new cc.EaseRateAction();
  152. if (ret)
  153. ret.initWithAction(action, rate);
  154. return ret;
  155. };
  156. /**
  157. * cc.EaseIn action with a rate
  158. * @class
  159. * @extends cc.EaseRateAction
  160. */
  161. cc.EaseIn = cc.EaseRateAction.extend(/** @lends cc.EaseIn# */{
  162. /**
  163. * @param {Number} time1
  164. */
  165. update:function (time1) {
  166. this._inner.update(Math.pow(time1, this._rate));
  167. },
  168. /**
  169. * @return {cc.ActionInterval}
  170. */
  171. reverse:function () {
  172. return cc.EaseIn.create(this._inner.reverse(), 1 / this._rate);
  173. },
  174. clone:function(){
  175. var action = new cc.EaseIn();
  176. action.initWithAction(this._inner.clone(), this._rate);
  177. return action;
  178. }
  179. });
  180. /** Creates the action with the inner action and the rate parameter
  181. * @param {cc.ActionInterval} action
  182. * @param {Number} rate
  183. * @return {cc.EaseIn}
  184. * @example
  185. * // example
  186. * var moveEaseIn = cc.EaseIn.create(action, 3.0);
  187. */
  188. cc.EaseIn.create = function (action, rate) {
  189. var ret = new cc.EaseIn();
  190. if (ret)
  191. ret.initWithAction(action, rate);
  192. return ret;
  193. };
  194. /**
  195. * cc.EaseOut action with a rate
  196. * @class
  197. * @extends cc.EaseRateAction
  198. */
  199. cc.EaseOut = cc.EaseRateAction.extend(/** @lends cc.EaseOut# */{
  200. /**
  201. * @param {Number} time1
  202. */
  203. update:function (time1) {
  204. this._inner.update(Math.pow(time1, 1 / this._rate));
  205. },
  206. /**
  207. * @return {cc.ActionInterval}
  208. */
  209. reverse:function () {
  210. return cc.EaseOut.create(this._inner.reverse(), 1 / this._rate);
  211. },
  212. clone:function(){
  213. var action = new cc.EaseOut();
  214. action.initWithAction(this._inner.clone(),this._rate);
  215. return action;
  216. }
  217. });
  218. /** Creates the action with the inner action and the rate parameter
  219. * @param {cc.ActionInterval} action
  220. * @param {Number} rate
  221. * @return {cc.EaseOut}
  222. * @example
  223. * // example
  224. * var moveEaseOut = cc.EaseOut.create(action, 3.0);
  225. */
  226. cc.EaseOut.create = function (action, rate) {
  227. var ret = new cc.EaseOut();
  228. if (ret)
  229. ret.initWithAction(action, rate);
  230. return ret;
  231. };
  232. /**
  233. * cc.EaseInOut action with a rate
  234. * @class
  235. * @extends cc.EaseRateAction
  236. */
  237. cc.EaseInOut = cc.EaseRateAction.extend(/** @lends cc.EaseInOut# */{
  238. /**
  239. * @param {Number} time1
  240. */
  241. update:function (time1) {
  242. time1 *= 2;
  243. if (time1 < 1)
  244. this._inner.update(0.5 * Math.pow(time1, this._rate));
  245. else
  246. this._inner.update(1.0 - 0.5 * Math.pow(2 - time1, this._rate));
  247. },
  248. clone:function(){
  249. var action = new cc.EaseInOut();
  250. action.initWithAction(this._inner.clone(), this._rate);
  251. return action;
  252. },
  253. /**
  254. * @return {cc.ActionInterval}
  255. */
  256. reverse:function () {
  257. return cc.EaseInOut.create(this._inner.reverse(), this._rate);
  258. }
  259. });
  260. /** Creates the action with the inner action and the rate parameter
  261. * @param {cc.ActionInterval} action
  262. * @param {Number} rate
  263. * @return {cc.EaseInOut}
  264. * @example
  265. * // example
  266. * var moveEaseInOut = cc.EaseInOut.create(action, 3.0);
  267. */
  268. cc.EaseInOut.create = function (action, rate) {
  269. var ret = new cc.EaseInOut();
  270. if (ret)
  271. ret.initWithAction(action, rate);
  272. return ret;
  273. };
  274. /**
  275. * cc.Ease Exponential In
  276. * @class
  277. * @extends cc.ActionEase
  278. */
  279. cc.EaseExponentialIn = cc.ActionEase.extend(/** @lends cc.EaseExponentialIn# */{
  280. /**
  281. * @param {Number} time1
  282. */
  283. update:function (time1) {
  284. this._inner.update(time1 === 0 ? 0 : Math.pow(2, 10 * (time1 - 1)));
  285. },
  286. /**
  287. * @return {cc.ActionInterval}
  288. */
  289. reverse:function () {
  290. return cc.EaseExponentialOut.create(this._inner.reverse());
  291. },
  292. clone:function(){
  293. var action = new cc.EaseExponentialIn();
  294. action.initWithAction(this._inner.clone());
  295. return action;
  296. }
  297. });
  298. /** creates the action
  299. * @param {cc.ActionInterval} action
  300. * @return {cc.EaseExponentialIn}
  301. * @example
  302. * // example
  303. * var moveEaseExponentialIn = cc.EaseExponentialIn.create(action);
  304. */
  305. cc.EaseExponentialIn.create = function (action) {
  306. var ret = new cc.EaseExponentialIn();
  307. if (ret)
  308. ret.initWithAction(action);
  309. return ret;
  310. };
  311. /**
  312. * Ease Exponential Out
  313. * @class
  314. * @extends cc.ActionEase
  315. */
  316. cc.EaseExponentialOut = cc.ActionEase.extend(/** @lends cc.EaseExponentialOut# */{
  317. /**
  318. * @param {Number} time1
  319. */
  320. update:function (time1) {
  321. this._inner.update(time1 == 1 ? 1 : (-(Math.pow(2, -10 * time1)) + 1));
  322. },
  323. /**
  324. * @return {cc.ActionInterval}
  325. */
  326. reverse:function () {
  327. return cc.EaseExponentialIn.create(this._inner.reverse());
  328. },
  329. clone:function(){
  330. var action = new cc.EaseExponentialOut();
  331. action.initWithAction(this._inner.clone());
  332. return action;
  333. }
  334. });
  335. /** creates the action
  336. * @param {cc.ActionInterval} action
  337. * @return {cc.EaseExponentialOut}
  338. * @example
  339. * // example
  340. * var moveEaseExponentialOut = cc.EaseExponentialOut.create(action);
  341. */
  342. cc.EaseExponentialOut.create = function (action) {
  343. var ret = new cc.EaseExponentialOut();
  344. if (ret)
  345. ret.initWithAction(action);
  346. return ret;
  347. };
  348. /**
  349. * Ease Exponential InOut
  350. * @class
  351. * @extends cc.ActionEase
  352. */
  353. cc.EaseExponentialInOut = cc.ActionEase.extend(/** @lends cc.EaseExponentialInOut# */{
  354. /**
  355. * @param {Number} time
  356. */
  357. update:function (time) {
  358. if( time != 1 && time !== 0) {
  359. time *= 2;
  360. if (time < 1)
  361. time = 0.5 * Math.pow(2, 10 * (time - 1));
  362. else
  363. time = 0.5 * (-Math.pow(2, -10 * (time - 1)) + 2);
  364. }
  365. this._inner.update(time);
  366. },
  367. /**
  368. * @return {cc.EaseExponentialInOut}
  369. */
  370. reverse:function () {
  371. return cc.EaseExponentialInOut.create(this._inner.reverse());
  372. },
  373. clone:function(){
  374. var action = new cc.EaseExponentialInOut();
  375. action.initWithAction(this._inner.clone());
  376. return action;
  377. }
  378. });
  379. /** creates the action
  380. * @param {cc.ActionInterval} action
  381. * @return {cc.EaseExponentialInOut}
  382. * @example
  383. * // example
  384. * var moveEaseExponentialInOut = cc.EaseExponentialInOut.create(action);
  385. */
  386. cc.EaseExponentialInOut.create = function (action) {
  387. var ret = new cc.EaseExponentialInOut();
  388. if (ret)
  389. ret.initWithAction(action);
  390. return ret;
  391. };
  392. /**
  393. * Ease Sine In
  394. * @class
  395. * @extends cc.ActionEase
  396. */
  397. cc.EaseSineIn = cc.ActionEase.extend(/** @lends cc.EaseSineIn# */{
  398. /**
  399. * @param {Number} time1
  400. */
  401. update:function (time1) {
  402. time1 = time1===0 || time1==1 ? time1 : -1 * Math.cos(time1 * Math.PI / 2) + 1;
  403. this._inner.update(time1);
  404. },
  405. /**
  406. * @return {cc.ActionInterval}
  407. */
  408. reverse:function () {
  409. return cc.EaseSineOut.create(this._inner.reverse());
  410. },
  411. clone:function(){
  412. var action = new cc.EaseSineIn();
  413. action.initWithAction(this._inner.clone());
  414. return action;
  415. }
  416. });
  417. /** creates the action
  418. * @param {cc.ActionInterval} action
  419. * @return {cc.EaseSineIn}
  420. * @example
  421. * // example
  422. * var moveSineIn = cc.EaseSineIn.create(action);
  423. */
  424. cc.EaseSineIn.create = function (action) {
  425. var ret = new cc.EaseSineIn();
  426. if (ret)
  427. ret.initWithAction(action);
  428. return ret;
  429. };
  430. /**
  431. * Ease Sine Out
  432. * @class
  433. * @extends cc.ActionEase
  434. */
  435. cc.EaseSineOut = cc.ActionEase.extend(/** @lends cc.EaseSineOut# */{
  436. /**
  437. * @param {Number} time1
  438. */
  439. update:function (time1) {
  440. time1 = time1===0 || time1==1 ? time1 : Math.sin(time1 * Math.PI / 2);
  441. this._inner.update(time1);
  442. },
  443. /**
  444. * @return {cc.ActionInterval}
  445. */
  446. reverse:function () {
  447. return cc.EaseSineIn.create(this._inner.reverse());
  448. },
  449. clone:function(){
  450. var action = new cc.EaseSineOut();
  451. action.initWithAction(this._inner.clone());
  452. return action;
  453. }
  454. });
  455. /** creates the action
  456. * @param {cc.ActionInterval} action
  457. * @return {cc.EaseSineOut}
  458. * @example
  459. * // example
  460. * var moveEaseOut = cc.EaseSineOut.create(action);
  461. */
  462. cc.EaseSineOut.create = function (action) {
  463. var ret = new cc.EaseSineOut();
  464. if (ret)
  465. ret.initWithAction(action);
  466. return ret;
  467. };
  468. /**
  469. * Ease Sine InOut
  470. * @class
  471. * @extends cc.ActionEase
  472. */
  473. cc.EaseSineInOut = cc.ActionEase.extend(/** @lends cc.EaseSineInOut# */{
  474. /**
  475. * @param {Number} time1
  476. */
  477. update:function (time1) {
  478. time1 = time1===0 || time1==1 ? time1 : -0.5 * (Math.cos(Math.PI * time1) - 1);
  479. this._inner.update(time1);
  480. },
  481. clone:function(){
  482. var action = new cc.EaseSineInOut();
  483. action.initWithAction(this._inner.clone());
  484. return action;
  485. },
  486. /**
  487. * @return {cc.ActionInterval}
  488. */
  489. reverse:function () {
  490. return cc.EaseSineInOut.create(this._inner.reverse());
  491. }
  492. });
  493. /** creates the action
  494. * @param {cc.ActionInterval} action
  495. * @return {cc.EaseSineInOut}
  496. * @example
  497. * // example
  498. * var moveEaseSineInOut = cc.EaseSineInOut.create(action);
  499. */
  500. cc.EaseSineInOut.create = function (action) {
  501. var ret = new cc.EaseSineInOut();
  502. if (ret)
  503. ret.initWithAction(action);
  504. return ret;
  505. };
  506. /**
  507. * Ease Elastic abstract class
  508. * @class
  509. * @extends cc.ActionEase
  510. */
  511. cc.EaseElastic = cc.ActionEase.extend(/** @lends cc.EaseElastic# */{
  512. _period:null,
  513. ctor:function(){
  514. cc.ActionEase.prototype.ctor.call(this);
  515. this._period = 0.3;
  516. },
  517. /** get period of the wave in radians. default is 0.3
  518. * @return {Number}
  519. */
  520. getPeriod:function () {
  521. return this._period;
  522. },
  523. /** set period of the wave in radians.
  524. * @param {Number} period
  525. */
  526. setPeriod:function (period) {
  527. this._period = period;
  528. },
  529. /** Initializes the action with the inner action and the period in radians (default is 0.3)
  530. * @param {cc.ActionInterval} action
  531. * @param {Number} [period=0.3]
  532. * @return {Boolean}
  533. */
  534. initWithAction:function (action, period) {
  535. cc.ActionEase.prototype.initWithAction.call(this, action);
  536. this._period = (period == null) ? 0.3 : period;
  537. return true;
  538. },
  539. /**
  540. * @return {Null}
  541. */
  542. reverse:function () {
  543. cc.log("cc.EaseElastic.reverse(): it should be overridden in subclass.");
  544. },
  545. clone:function(){
  546. var action = new cc.EaseElastic();
  547. action.initWithAction(this._inner.clone(), this._period);
  548. return action;
  549. }
  550. });
  551. /** Creates the action with the inner action and the period in radians (default is 0.3)
  552. * @param {cc.ActionInterval} action
  553. * @param {Number} [period=0.3]
  554. * @return {cc.EaseElastic}
  555. * @example
  556. * // example
  557. * var moveEaseElastic = cc.EaseElastic.create(action, 3.0);
  558. */
  559. cc.EaseElastic.create = function (action, period) {
  560. var ret = new cc.EaseElastic();
  561. if (ret && ret.initWithAction(action, period))
  562. return ret;
  563. return null;
  564. };
  565. /**
  566. * Ease Elastic In action.
  567. * @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action.
  568. * @class
  569. * @extends cc.EaseElastic
  570. */
  571. cc.EaseElasticIn = cc.EaseElastic.extend(/** @lends cc.EaseElasticIn# */{
  572. /**
  573. * @param {Number} time1
  574. */
  575. update:function (time1) {
  576. var newT = 0;
  577. if (time1 === 0 || time1 === 1) {
  578. newT = time1;
  579. } else {
  580. var s = this._period / 4;
  581. time1 = time1 - 1;
  582. newT = -Math.pow(2, 10 * time1) * Math.sin((time1 - s) * Math.PI * 2 / this._period);
  583. }
  584. this._inner.update(newT);
  585. },
  586. /**
  587. * @return {cc.ActionInterval}
  588. */
  589. reverse:function () {
  590. return cc.EaseElasticOut.create(this._inner.reverse(), this._period);
  591. },
  592. clone:function(){
  593. var action = new cc.EaseElasticIn();
  594. action.initWithAction(this._inner.clone(), this._period);
  595. return action;
  596. }
  597. });
  598. /** Creates the action with the inner action and the period in radians (default is 0.3)
  599. * @param {cc.ActionInterval} action
  600. * @param {Number} [period=]
  601. * @return {cc.EaseElasticIn}
  602. * @example
  603. * // example
  604. * var moveEaseElasticIn = cc.EaseElasticIn.create(action, 3.0);
  605. */
  606. cc.EaseElasticIn.create = function (action, period) {
  607. var ret = new cc.EaseElasticIn();
  608. if (ret && ret.initWithAction(action, period))
  609. return ret;
  610. return null;
  611. };
  612. /**
  613. * Ease Elastic Out action.
  614. * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action.
  615. * @class
  616. * @extends cc.EaseElastic
  617. */
  618. cc.EaseElasticOut = cc.EaseElastic.extend(/** @lends cc.EaseElasticOut# */{
  619. /**
  620. * @param {Number} time1
  621. */
  622. update:function (time1) {
  623. var newT = 0;
  624. if (time1 === 0 || time1 == 1) {
  625. newT = time1;
  626. } else {
  627. var s = this._period / 4;
  628. newT = Math.pow(2, -10 * time1) * Math.sin((time1 - s) * Math.PI * 2 / this._period) + 1;
  629. }
  630. this._inner.update(newT);
  631. },
  632. /**
  633. * @return {cc.ActionInterval}
  634. */
  635. reverse:function () {
  636. return cc.EaseElasticIn.create(this._inner.reverse(), this._period);
  637. },
  638. clone:function(){
  639. var action = new cc.EaseElasticOut();
  640. action.initWithAction(this._inner.clone(), this._period);
  641. return action;
  642. }
  643. });
  644. /** Creates the action with the inner action and the period in radians (default is 0.3)
  645. * @param {cc.ActionInterval} action
  646. * @param {Number} [period=0.3]
  647. * @return {cc.EaseElasticOut}
  648. * @example
  649. * // example
  650. * var moveEaseElasticOut = cc.EaseElasticOut.create(action, 3.0);
  651. */
  652. cc.EaseElasticOut.create = function (action, period) {
  653. var ret = new cc.EaseElasticOut();
  654. if (ret)
  655. ret.initWithAction(action, period);
  656. return ret;
  657. };
  658. /**
  659. * Ease Elastic InOut action.
  660. * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action.
  661. * @class
  662. * @extends cc.EaseElastic
  663. */
  664. cc.EaseElasticInOut = cc.EaseElastic.extend(/** @lends cc.EaseElasticInOut# */{
  665. /**
  666. * @param {Number} time1
  667. */
  668. update:function (time1) {
  669. var newT = 0;
  670. var locPeriod = this._period
  671. if (time1 === 0 || time1 == 1) {
  672. newT = time1;
  673. } else {
  674. time1 = time1 * 2;
  675. if (!locPeriod)
  676. locPeriod = this._period = 0.3 * 1.5;
  677. var s = locPeriod / 4;
  678. time1 = time1 - 1;
  679. if (time1 < 0)
  680. newT = -0.5 * Math.pow(2, 10 * time1) * Math.sin((time1 - s) * Math.PI * 2 / locPeriod);
  681. else
  682. newT = Math.pow(2, -10 * time1) * Math.sin((time1 - s) * Math.PI * 2 / locPeriod) * 0.5 + 1;
  683. }
  684. this._inner.update(newT);
  685. },
  686. /**
  687. * @return {cc.ActionInterval}
  688. */
  689. reverse:function () {
  690. return cc.EaseElasticInOut.create(this._inner.reverse(), this._period);
  691. },
  692. clone:function(){
  693. var action = new cc.EaseElasticInOut();
  694. action.initWithAction(this._inner.clone(), this._period);
  695. return action;
  696. }
  697. });
  698. /** Creates the action with the inner action and the period in radians (default is 0.3)
  699. * @param {cc.ActionInterval} action
  700. * @param {Number} [period=0.3]
  701. * @return {cc.EaseElasticInOut}
  702. * @example
  703. * // example
  704. * var moveEaseElasticInOut = cc.EaseElasticInOut.create(action, 3.0);
  705. */
  706. cc.EaseElasticInOut.create = function (action, period) {
  707. var ret = new cc.EaseElasticInOut();
  708. if (ret)
  709. ret.initWithAction(action, period);
  710. return ret;
  711. };
  712. /**
  713. * cc.EaseBounce abstract class.
  714. * @class
  715. * @extends cc.ActionEase
  716. */
  717. cc.EaseBounce = cc.ActionEase.extend(/** @lends cc.EaseBounce# */{
  718. /**
  719. * @param {Number} time1
  720. * @return {Number}
  721. */
  722. bounceTime:function (time1) {
  723. if (time1 < 1 / 2.75) {
  724. return 7.5625 * time1 * time1;
  725. } else if (time1 < 2 / 2.75) {
  726. time1 -= 1.5 / 2.75;
  727. return 7.5625 * time1 * time1 + 0.75;
  728. } else if (time1 < 2.5 / 2.75) {
  729. time1 -= 2.25 / 2.75;
  730. return 7.5625 * time1 * time1 + 0.9375;
  731. }
  732. time1 -= 2.625 / 2.75;
  733. return 7.5625 * time1 * time1 + 0.984375;
  734. },
  735. clone:function(){
  736. var action = new cc.EaseBounce();
  737. action.initWithAction(this._inner.clone());
  738. return action;
  739. },
  740. /**
  741. * @return {cc.ActionInterval}
  742. */
  743. reverse:function () {
  744. return cc.EaseBounce.create(this._inner.reverse());
  745. }
  746. });
  747. /** creates the action
  748. * @param {cc.ActionInterval} action
  749. * @return {cc.EaseBounce}
  750. * @example
  751. * // example
  752. * var moveEaseBounce = cc.EaseBounce.create(action);
  753. */
  754. cc.EaseBounce.create = function (action) {
  755. var ret = new cc.EaseBounce();
  756. if (ret)
  757. ret.initWithAction(action);
  758. return ret;
  759. };
  760. /**
  761. * cc.EaseBounceIn action.
  762. * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action.
  763. * @class
  764. * @extends cc.EaseBounce
  765. */
  766. cc.EaseBounceIn = cc.EaseBounce.extend(/** @lends cc.EaseBounceIn# */{
  767. /**
  768. * @param {Number} time1
  769. */
  770. update:function (time1) {
  771. var newT = 1 - this.bounceTime(1 - time1);
  772. this._inner.update(newT);
  773. },
  774. /**
  775. * @return {cc.ActionInterval}
  776. */
  777. reverse:function () {
  778. return cc.EaseBounceOut.create(this._inner.reverse());
  779. },
  780. clone:function(){
  781. var action = new cc.EaseBounceIn();
  782. action.initWithAction(this._inner.clone());
  783. return action;
  784. }
  785. });
  786. /** creates the action
  787. * @param {cc.ActionInterval} action
  788. * @return {cc.EaseBounceIn}
  789. * @example
  790. * // example
  791. * var moveEaseBounceIn = cc.EaseBounceIn.create(action);
  792. */
  793. cc.EaseBounceIn.create = function (action) {
  794. var ret = new cc.EaseBounceIn();
  795. if (ret)
  796. ret.initWithAction(action);
  797. return ret;
  798. };
  799. /**
  800. * cc.EaseBounceOut action.
  801. * @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action.
  802. * @class
  803. * @extends cc.EaseBounce
  804. */
  805. cc.EaseBounceOut = cc.EaseBounce.extend(/** @lends cc.EaseBounceOut# */{
  806. /**
  807. * @param {Number} time1
  808. */
  809. update:function (time1) {
  810. var newT = this.bounceTime(time1);
  811. this._inner.update(newT);
  812. },
  813. /**
  814. * @return {cc.ActionInterval}
  815. */
  816. reverse:function () {
  817. return cc.EaseBounceIn.create(this._inner.reverse());
  818. },
  819. clone:function(){
  820. var action = new cc.EaseBounceOut();
  821. action.initWithAction(this._inner.clone());
  822. return action;
  823. }
  824. });
  825. /** creates the action
  826. * @param {cc.ActionInterval} action
  827. * @return {cc.EaseBounceOut}
  828. * @example
  829. * // example
  830. * var moveEaseBounceOut = cc.EaseBounceOut.create(action);
  831. */
  832. cc.EaseBounceOut.create = function (action) {
  833. var ret = new cc.EaseBounceOut();
  834. if (ret)
  835. ret.initWithAction(action);
  836. return ret;
  837. };
  838. /**
  839. * cc.EaseBounceInOut action.
  840. * @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action.
  841. * @class
  842. * @extends cc.EaseBounce
  843. */
  844. cc.EaseBounceInOut = cc.EaseBounce.extend(/** @lends cc.EaseBounceInOut# */{
  845. /**
  846. * @param {Number} time1
  847. */
  848. update:function (time1) {
  849. var newT = 0;
  850. if (time1 < 0.5) {
  851. time1 = time1 * 2;
  852. newT = (1 - this.bounceTime(1 - time1)) * 0.5;
  853. } else {
  854. newT = this.bounceTime(time1 * 2 - 1) * 0.5 + 0.5;
  855. }
  856. this._inner.update(newT);
  857. },
  858. clone:function(){
  859. var action = new cc.EaseBounceInOut();
  860. action.initWithAction(this._inner.clone());
  861. return action;
  862. },
  863. /**
  864. * @return {cc.ActionInterval}
  865. */
  866. reverse:function () {
  867. return cc.EaseBounceInOut.create(this._inner.reverse());
  868. }
  869. });
  870. /** creates the action
  871. * @param {cc.ActionInterval} action
  872. * @return {cc.EaseBounceInOut}
  873. * @example
  874. * // example
  875. * var moveEaseBounceInOut = cc.EaseBounceInOut.create(action);
  876. */
  877. cc.EaseBounceInOut.create = function (action) {
  878. var ret = new cc.EaseBounceInOut();
  879. if (ret)
  880. ret.initWithAction(action);
  881. return ret;
  882. };
  883. /**
  884. * cc.EaseBackIn action.
  885. * @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action.
  886. * @class
  887. * @extends cc.ActionEase
  888. */
  889. cc.EaseBackIn = cc.ActionEase.extend(/** @lends cc.EaseBackIn# */{
  890. /**
  891. * @param {Number} time1
  892. */
  893. update:function (time1) {
  894. var overshoot = 1.70158;
  895. time1 = time1===0 || time1==1 ? time1 : time1 * time1 * ((overshoot + 1) * time1 - overshoot);
  896. this._inner.update(time1);
  897. },
  898. /**
  899. * @return {cc.ActionInterval}
  900. */
  901. reverse:function () {
  902. return cc.EaseBackOut.create(this._inner.reverse());
  903. },
  904. clone:function(){
  905. var action = new cc.EaseBackIn();
  906. action.initWithAction(this._inner.clone());
  907. return action;
  908. }
  909. });
  910. /** creates the action
  911. * @param {cc.ActionInterval} action
  912. * @return {cc.EaseBackIn}
  913. * @example
  914. * // example
  915. * var moveEaseBackIn = cc.EaseBackIn.create(action);
  916. */
  917. cc.EaseBackIn.create = function (action) {
  918. var ret = new cc.EaseBackIn();
  919. if (ret)
  920. ret.initWithAction(action);
  921. return ret;
  922. };
  923. /**
  924. * cc.EaseBackOut action.
  925. * @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action.
  926. * @class
  927. * @extends cc.ActionEase
  928. */
  929. cc.EaseBackOut = cc.ActionEase.extend(/** @lends cc.EaseBackOut# */{
  930. /**
  931. * @param {Number} time1
  932. */
  933. update:function (time1) {
  934. var overshoot = 1.70158;
  935. time1 = time1 - 1;
  936. this._inner.update(time1 * time1 * ((overshoot + 1) * time1 + overshoot) + 1);
  937. },
  938. /**
  939. * @return {cc.ActionInterval}
  940. */
  941. reverse:function () {
  942. return cc.EaseBackIn.create(this._inner.reverse());
  943. },
  944. clone:function(){
  945. var action = new cc.EaseBackOut();
  946. action.initWithAction(this._inner.clone());
  947. return action;
  948. }
  949. });
  950. /** creates the action
  951. * @param {cc.ActionInterval} action
  952. * @return {cc.EaseBackOut}
  953. * @example
  954. * // example
  955. * var moveEaseBackOut = cc.EaseBackOut.create(action);
  956. */
  957. cc.EaseBackOut.create = function (action) {
  958. var ret = new cc.EaseBackOut();
  959. if (ret)
  960. ret.initWithAction(action);
  961. return ret;
  962. };
  963. /**
  964. * cc.EaseBackInOut action.
  965. * @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action.
  966. * @class
  967. * @extends cc.ActionEase
  968. */
  969. cc.EaseBackInOut = cc.ActionEase.extend(/** @lends cc.EaseBackInOut# */{
  970. /**
  971. * @param {Number} time1
  972. */
  973. update:function (time1) {
  974. var overshoot = 1.70158 * 1.525;
  975. time1 = time1 * 2;
  976. if (time1 < 1) {
  977. this._inner.update((time1 * time1 * ((overshoot + 1) * time1 - overshoot)) / 2);
  978. } else {
  979. time1 = time1 - 2;
  980. this._inner.update((time1 * time1 * ((overshoot + 1) * time1 + overshoot)) / 2 + 1);
  981. }
  982. },
  983. clone:function(){
  984. var action = new cc.EaseBackInOut();
  985. action.initWithAction(this._inner.clone());
  986. return action;
  987. },
  988. /**
  989. * @return {cc.ActionInterval}
  990. */
  991. reverse:function () {
  992. return cc.EaseBackInOut.create(this._inner.reverse());
  993. }
  994. });
  995. /** creates the action
  996. * @param {cc.ActionInterval} action
  997. * @return {cc.EaseBackInOut}
  998. * @example
  999. * // example
  1000. * var moveEaseBackInOut = cc.EaseBackInOut.create(action);
  1001. */
  1002. cc.EaseBackInOut.create = function (action) {
  1003. var ret = new cc.EaseBackInOut();
  1004. if (ret)
  1005. ret.initWithAction(action);
  1006. return ret;
  1007. };