CCActionInterval.h 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695
  1. /****************************************************************************
  2. Copyright (c) 2008-2010 Ricardo Quesada
  3. Copyright (c) 2011 Zynga Inc.
  4. Copyright (c) 2010-2012 cocos2d-x.org
  5. Copyright (c) 2013-2017 Chukong Technologies Inc.
  6. http://www.cocos2d-x.org
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. ****************************************************************************/
  23. #ifndef __ACTION_CCINTERVAL_ACTION_H__
  24. #define __ACTION_CCINTERVAL_ACTION_H__
  25. #include <vector>
  26. #include "2d/CCAction.h"
  27. #include "2d/CCAnimation.h"
  28. #include "base/CCProtocols.h"
  29. #include "base/CCVector.h"
  30. NS_CC_BEGIN
  31. class Node;
  32. class SpriteFrame;
  33. class EventCustom;
  34. /**
  35. * @addtogroup actions
  36. * @{
  37. */
  38. /** @class ActionInterval
  39. @brief An interval action is an action that takes place within a certain period of time.
  40. It has an start time, and a finish time. The finish time is the parameter
  41. duration plus the start time.
  42. These ActionInterval actions have some interesting properties, like:
  43. - They can run normally (default)
  44. - They can run reversed with the reverse method
  45. - They can run with the time altered with the Accelerate, AccelDeccel and Speed actions.
  46. For example, you can simulate a Ping Pong effect running the action normally and
  47. then running it again in Reverse mode.
  48. Example:
  49. @code
  50. auto action = MoveBy::create(1.0f, Vec2::ONE);
  51. auto pingPongAction = Sequence::create(action, action->reverse(), nullptr);
  52. @endcode
  53. */
  54. class CC_DLL ActionInterval : public FiniteTimeAction
  55. {
  56. public:
  57. /** How many seconds had elapsed since the actions started to run.
  58. *
  59. * @return The seconds had elapsed since the actions started to run.
  60. */
  61. float getElapsed() { return _elapsed; }
  62. /** Sets the amplitude rate, extension in GridAction
  63. *
  64. * @param amp The amplitude rate.
  65. */
  66. void setAmplitudeRate(float amp);
  67. /** Gets the amplitude rate, extension in GridAction
  68. *
  69. * @return The amplitude rate.
  70. */
  71. float getAmplitudeRate();
  72. //
  73. // Overrides
  74. //
  75. virtual bool isDone() const override;
  76. /**
  77. * @param dt in seconds
  78. */
  79. virtual void step(float dt) override;
  80. virtual void startWithTarget(Node *target) override;
  81. virtual ActionInterval* reverse() const override
  82. {
  83. CC_ASSERT(0);
  84. return nullptr;
  85. }
  86. virtual ActionInterval *clone() const override
  87. {
  88. CC_ASSERT(0);
  89. return nullptr;
  90. }
  91. CC_CONSTRUCTOR_ACCESS:
  92. /** initializes the action */
  93. bool initWithDuration(float d);
  94. protected:
  95. float _elapsed;
  96. bool _firstTick;
  97. bool _done;
  98. protected:
  99. bool sendUpdateEventToScript(float dt, Action *actionObject);
  100. };
  101. /** @class Sequence
  102. * @brief Runs actions sequentially, one after another.
  103. */
  104. class CC_DLL Sequence : public ActionInterval
  105. {
  106. public:
  107. /** Helper constructor to create an array of sequenceable actions.
  108. *
  109. * @return An autoreleased Sequence object.
  110. */
  111. #if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
  112. // VS2013 does not support nullptr in variable args lists and variadic templates are also not supported
  113. typedef FiniteTimeAction* M;
  114. static Sequence* create(M m1, std::nullptr_t listEnd) { return variadicCreate(m1, NULL); }
  115. static Sequence* create(M m1, M m2, std::nullptr_t listEnd) { return variadicCreate(m1, m2, NULL); }
  116. static Sequence* create(M m1, M m2, M m3, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, NULL); }
  117. static Sequence* create(M m1, M m2, M m3, M m4, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, NULL); }
  118. static Sequence* create(M m1, M m2, M m3, M m4, M m5, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, NULL); }
  119. static Sequence* create(M m1, M m2, M m3, M m4, M m5, M m6, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, NULL); }
  120. static Sequence* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, NULL); }
  121. static Sequence* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, m8, NULL); }
  122. static Sequence* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, M m9, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, m8, m9, NULL); }
  123. static Sequence* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, M m9, M m10, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, NULL); }
  124. // On WP8 for variable argument lists longer than 10 items, use the other create functions or variadicCreate with NULL as the last argument
  125. static Sequence* variadicCreate(FiniteTimeAction* item, ...);
  126. #else
  127. static Sequence* create(FiniteTimeAction *action1, ...) CC_REQUIRES_NULL_TERMINATION;
  128. #endif
  129. /** Helper constructor to create an array of sequenceable actions given an array.
  130. * @code
  131. * When this function bound to the js or lua,the input params changed
  132. * in js :var create(var object1,var object2, ...)
  133. * in lua :local create(local object1,local object2, ...)
  134. * @endcode
  135. *
  136. * @param arrayOfActions An array of sequenceable actions.
  137. * @return An autoreleased Sequence object.
  138. */
  139. static Sequence* create(const Vector<FiniteTimeAction*>& arrayOfActions);
  140. /** Helper constructor to create an array of sequence-able actions.
  141. *
  142. * @param action1 The first sequenceable action.
  143. * @param args The va_list variable.
  144. * @return An autoreleased Sequence object.
  145. * @js NA
  146. */
  147. static Sequence* createWithVariableList(FiniteTimeAction *action1, va_list args);
  148. /** Creates the action.
  149. * @param actionOne The first sequenceable action.
  150. * @param actionTwo The second sequenceable action.
  151. * @return An autoreleased Sequence object.
  152. * @js NA
  153. */
  154. static Sequence* createWithTwoActions(FiniteTimeAction *actionOne, FiniteTimeAction *actionTwo);
  155. //
  156. // Overrides
  157. //
  158. virtual Sequence* clone() const override;
  159. virtual Sequence* reverse() const override;
  160. virtual void startWithTarget(Node *target) override;
  161. virtual void stop() override;
  162. virtual bool isDone() const override;
  163. /**
  164. * @param t In seconds.
  165. */
  166. virtual void update(float t) override;
  167. CC_CONSTRUCTOR_ACCESS:
  168. Sequence();
  169. virtual ~Sequence();
  170. /** initializes the action */
  171. bool initWithTwoActions(FiniteTimeAction *pActionOne, FiniteTimeAction *pActionTwo);
  172. bool init(const Vector<FiniteTimeAction*>& arrayOfActions);
  173. protected:
  174. FiniteTimeAction *_actions[2];
  175. float _split;
  176. int _last;
  177. private:
  178. CC_DISALLOW_COPY_AND_ASSIGN(Sequence);
  179. };
  180. /** @class Repeat
  181. * @brief Repeats an action a number of times.
  182. * To repeat an action forever use the RepeatForever action.
  183. */
  184. class CC_DLL Repeat : public ActionInterval
  185. {
  186. public:
  187. /** Creates a Repeat action. Times is an unsigned integer between 1 and pow(2,30).
  188. *
  189. * @param action The action needs to repeat.
  190. * @param times The repeat times.
  191. * @return An autoreleased Repeat object.
  192. */
  193. static Repeat* create(FiniteTimeAction *action, unsigned int times);
  194. /** Sets the inner action.
  195. *
  196. * @param action The inner action.
  197. */
  198. void setInnerAction(FiniteTimeAction *action)
  199. {
  200. if (_innerAction != action)
  201. {
  202. CC_SAFE_RETAIN(action);
  203. CC_SAFE_RELEASE(_innerAction);
  204. _innerAction = action;
  205. }
  206. }
  207. /** Gets the inner action.
  208. *
  209. * @return The inner action.
  210. */
  211. FiniteTimeAction* getInnerAction()
  212. {
  213. return _innerAction;
  214. }
  215. //
  216. // Overrides
  217. //
  218. virtual Repeat* clone() const override;
  219. virtual Repeat* reverse() const override;
  220. virtual void startWithTarget(Node *target) override;
  221. virtual void stop(void) override;
  222. /**
  223. * @param dt In seconds.
  224. */
  225. virtual void update(float dt) override;
  226. virtual bool isDone(void) const override;
  227. CC_CONSTRUCTOR_ACCESS:
  228. Repeat() {}
  229. virtual ~Repeat();
  230. /** initializes a Repeat action. Times is an unsigned integer between 1 and pow(2,30) */
  231. bool initWithAction(FiniteTimeAction *pAction, unsigned int times);
  232. protected:
  233. unsigned int _times;
  234. unsigned int _total;
  235. float _nextDt;
  236. bool _actionInstant;
  237. /** Inner action */
  238. FiniteTimeAction *_innerAction;
  239. private:
  240. CC_DISALLOW_COPY_AND_ASSIGN(Repeat);
  241. };
  242. /** @class RepeatForever
  243. * @brief Repeats an action for ever.
  244. To repeat the an action for a limited number of times use the Repeat action.
  245. * @warning This action can't be Sequenceable because it is not an IntervalAction.
  246. */
  247. class CC_DLL RepeatForever : public ActionInterval
  248. {
  249. public:
  250. /** Creates the action.
  251. *
  252. * @param action The action need to repeat forever.
  253. * @return An autoreleased RepeatForever object.
  254. */
  255. static RepeatForever* create(ActionInterval *action);
  256. /** Sets the inner action.
  257. *
  258. * @param action The inner action.
  259. */
  260. void setInnerAction(ActionInterval *action)
  261. {
  262. if (_innerAction != action)
  263. {
  264. CC_SAFE_RELEASE(_innerAction);
  265. _innerAction = action;
  266. CC_SAFE_RETAIN(_innerAction);
  267. }
  268. }
  269. /** Gets the inner action.
  270. *
  271. * @return The inner action.
  272. */
  273. ActionInterval* getInnerAction()
  274. {
  275. return _innerAction;
  276. }
  277. //
  278. // Overrides
  279. //
  280. virtual RepeatForever* clone() const override;
  281. virtual RepeatForever* reverse(void) const override;
  282. virtual void startWithTarget(Node* target) override;
  283. /**
  284. * @param dt In seconds.
  285. */
  286. virtual void step(float dt) override;
  287. virtual bool isDone(void) const override;
  288. CC_CONSTRUCTOR_ACCESS:
  289. RepeatForever()
  290. : _innerAction(nullptr)
  291. {}
  292. virtual ~RepeatForever();
  293. /** initializes the action */
  294. bool initWithAction(ActionInterval *action);
  295. protected:
  296. /** Inner action */
  297. ActionInterval *_innerAction;
  298. private:
  299. CC_DISALLOW_COPY_AND_ASSIGN(RepeatForever);
  300. };
  301. /** @class Spawn
  302. * @brief Spawn a new action immediately
  303. */
  304. class CC_DLL Spawn : public ActionInterval
  305. {
  306. public:
  307. /** Helper constructor to create an array of spawned actions.
  308. * @code
  309. * When this function bound to the js or lua, the input params changed.
  310. * in js :var create(var object1,var object2, ...)
  311. * in lua :local create(local object1,local object2, ...)
  312. * @endcode
  313. *
  314. * @return An autoreleased Spawn object.
  315. */
  316. #if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
  317. // VS2013 does not support nullptr in variable args lists and variadic templates are also not supported.
  318. typedef FiniteTimeAction* M;
  319. static Spawn* create(M m1, std::nullptr_t listEnd) { return variadicCreate(m1, NULL); }
  320. static Spawn* create(M m1, M m2, std::nullptr_t listEnd) { return variadicCreate(m1, m2, NULL); }
  321. static Spawn* create(M m1, M m2, M m3, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, NULL); }
  322. static Spawn* create(M m1, M m2, M m3, M m4, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, NULL); }
  323. static Spawn* create(M m1, M m2, M m3, M m4, M m5, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, NULL); }
  324. static Spawn* create(M m1, M m2, M m3, M m4, M m5, M m6, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, NULL); }
  325. static Spawn* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, NULL); }
  326. static Spawn* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, m8, NULL); }
  327. static Spawn* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, M m9, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, m8, m9, NULL); }
  328. static Spawn* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, M m9, M m10, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, NULL); }
  329. // On WP8 for variable argument lists longer than 10 items, use the other create functions or createSpawn with NULL as the last argument.
  330. static Spawn* variadicCreate(FiniteTimeAction* item, ...);
  331. #else
  332. static Spawn* create(FiniteTimeAction *action1, ...) CC_REQUIRES_NULL_TERMINATION;
  333. #endif
  334. /** Helper constructor to create an array of spawned actions.
  335. *
  336. * @param action1 The first sequenceable action.
  337. * @param args The va_list variable.
  338. * @return An autoreleased Spawn object.
  339. * @js NA
  340. */
  341. static Spawn* createWithVariableList(FiniteTimeAction *action1, va_list args);
  342. /** Helper constructor to create an array of spawned actions given an array.
  343. *
  344. * @param arrayOfActions An array of spawned actions.
  345. * @return An autoreleased Spawn object.
  346. */
  347. static Spawn* create(const Vector<FiniteTimeAction*>& arrayOfActions);
  348. /** Creates the Spawn action.
  349. *
  350. * @param action1 The first spawned action.
  351. * @param action2 The second spawned action.
  352. * @return An autoreleased Spawn object.
  353. * @js NA
  354. */
  355. static Spawn* createWithTwoActions(FiniteTimeAction *action1, FiniteTimeAction *action2);
  356. //
  357. // Overrides
  358. //
  359. virtual Spawn* clone() const override;
  360. virtual Spawn* reverse() const override;
  361. virtual void startWithTarget(Node *target) override;
  362. virtual void stop() override;
  363. /**
  364. * @param time In seconds.
  365. */
  366. virtual void update(float time) override;
  367. CC_CONSTRUCTOR_ACCESS:
  368. Spawn();
  369. virtual ~Spawn();
  370. /** initializes the Spawn action with the 2 actions to spawn */
  371. bool initWithTwoActions(FiniteTimeAction *action1, FiniteTimeAction *action2);
  372. bool init(const Vector<FiniteTimeAction*>& arrayOfActions);
  373. protected:
  374. FiniteTimeAction *_one;
  375. FiniteTimeAction *_two;
  376. private:
  377. CC_DISALLOW_COPY_AND_ASSIGN(Spawn);
  378. };
  379. /** @class RotateTo
  380. * @brief Rotates a Node object to a certain angle by modifying it's rotation attribute.
  381. The direction will be decided by the shortest angle.
  382. */
  383. class CC_DLL RotateTo : public ActionInterval
  384. {
  385. public:
  386. /**
  387. * Creates the action with separate rotation angles.
  388. *
  389. * @param duration Duration time, in seconds.
  390. * @param dstAngleX In degreesCW.
  391. * @param dstAngleY In degreesCW.
  392. * @return An autoreleased RotateTo object.
  393. */
  394. static RotateTo* create(float duration, float dstAngleX, float dstAngleY);
  395. /**
  396. * Creates the action.
  397. *
  398. * @param duration Duration time, in seconds.
  399. * @param dstAngle In degreesCW.
  400. * @return An autoreleased RotateTo object.
  401. */
  402. static RotateTo* create(float duration, float dstAngle);
  403. /**
  404. * Creates the action with 3D rotation angles.
  405. * @param duration Duration time, in seconds.
  406. * @param dstAngle3D A Vec3 angle.
  407. * @return An autoreleased RotateTo object.
  408. */
  409. static RotateTo* create(float duration, const Vec3& dstAngle3D);
  410. //
  411. // Overrides
  412. //
  413. virtual RotateTo* clone() const override;
  414. virtual RotateTo* reverse() const override;
  415. virtual void startWithTarget(Node *target) override;
  416. /**
  417. * @param time In seconds.
  418. */
  419. virtual void update(float time) override;
  420. CC_CONSTRUCTOR_ACCESS:
  421. RotateTo();
  422. virtual ~RotateTo() {}
  423. /**
  424. * initializes the action
  425. * @param duration in seconds
  426. * @param dstAngleX in degreesCW
  427. * @param dstAngleY in degreesCW
  428. */
  429. bool initWithDuration(float duration, float dstAngleX, float dstAngleY);
  430. /**
  431. * initializes the action
  432. * @param duration in seconds
  433. */
  434. bool initWithDuration(float duration, const Vec3& dstAngle3D);
  435. /**
  436. * calculates the start and diff angles
  437. * @param dstAngle in degreesCW
  438. */
  439. void calculateAngles(float &startAngle, float &diffAngle, float dstAngle);
  440. protected:
  441. bool _is3D;
  442. Vec3 _dstAngle;
  443. Vec3 _startAngle;
  444. Vec3 _diffAngle;
  445. private:
  446. CC_DISALLOW_COPY_AND_ASSIGN(RotateTo);
  447. };
  448. /** @class RotateBy
  449. * @brief Rotates a Node object clockwise a number of degrees by modifying it's rotation attribute.
  450. */
  451. class CC_DLL RotateBy : public ActionInterval
  452. {
  453. public:
  454. /**
  455. * Creates the action.
  456. *
  457. * @param duration Duration time, in seconds.
  458. * @param deltaAngle In degreesCW.
  459. * @return An autoreleased RotateBy object.
  460. */
  461. static RotateBy* create(float duration, float deltaAngle);
  462. /**
  463. * Creates the action with separate rotation angles.
  464. *
  465. * @param duration Duration time, in seconds.
  466. * @param deltaAngleZ_X In degreesCW.
  467. * @param deltaAngleZ_Y In degreesCW.
  468. * @return An autoreleased RotateBy object.
  469. * @warning The physics body contained in Node doesn't support rotate with different x and y angle.
  470. */
  471. static RotateBy* create(float duration, float deltaAngleZ_X, float deltaAngleZ_Y);
  472. /** Creates the action with 3D rotation angles.
  473. *
  474. * @param duration Duration time, in seconds.
  475. * @param deltaAngle3D A Vec3 angle.
  476. * @return An autoreleased RotateBy object.
  477. */
  478. static RotateBy* create(float duration, const Vec3& deltaAngle3D);
  479. //
  480. // Override
  481. //
  482. virtual RotateBy* clone() const override;
  483. virtual RotateBy* reverse() const override;
  484. virtual void startWithTarget(Node *target) override;
  485. /**
  486. * @param time In seconds.
  487. */
  488. virtual void update(float time) override;
  489. CC_CONSTRUCTOR_ACCESS:
  490. RotateBy();
  491. virtual ~RotateBy() {}
  492. /** initializes the action */
  493. bool initWithDuration(float duration, float deltaAngle);
  494. /**
  495. * @warning The physics body contained in Node doesn't support rotate with different x and y angle.
  496. * @param deltaAngleZ_X in degreesCW
  497. * @param deltaAngleZ_Y in degreesCW
  498. */
  499. bool initWithDuration(float duration, float deltaAngleZ_X, float deltaAngleZ_Y);
  500. bool initWithDuration(float duration, const Vec3& deltaAngle3D);
  501. protected:
  502. bool _is3D;
  503. Vec3 _deltaAngle;
  504. Vec3 _startAngle;
  505. private:
  506. CC_DISALLOW_COPY_AND_ASSIGN(RotateBy);
  507. };
  508. /** @class MoveBy
  509. * @brief Moves a Node object x,y pixels by modifying it's position attribute.
  510. x and y are relative to the position of the object.
  511. Several MoveBy actions can be concurrently called, and the resulting
  512. movement will be the sum of individual movements.
  513. @since v2.1beta2-custom
  514. */
  515. class CC_DLL MoveBy : public ActionInterval
  516. {
  517. public:
  518. /**
  519. * Creates the action.
  520. *
  521. * @param duration Duration time, in seconds.
  522. * @param deltaPosition The delta distance in 2d, it's a Vec2 type.
  523. * @return An autoreleased MoveBy object.
  524. */
  525. static MoveBy* create(float duration, const Vec2& deltaPosition);
  526. /**
  527. * Creates the action.
  528. *
  529. * @param duration Duration time, in seconds.
  530. * @param deltaPosition The delta distance in 3d, it's a Vec3 type.
  531. * @return An autoreleased MoveBy object.
  532. */
  533. static MoveBy* create(float duration, const Vec3& deltaPosition);
  534. //
  535. // Overrides
  536. //
  537. virtual MoveBy* clone() const override;
  538. virtual MoveBy* reverse() const override;
  539. virtual void startWithTarget(Node *target) override;
  540. /**
  541. * @param time in seconds
  542. */
  543. virtual void update(float time) override;
  544. CC_CONSTRUCTOR_ACCESS:
  545. MoveBy():_is3D(false) {}
  546. virtual ~MoveBy() {}
  547. /** initializes the action */
  548. bool initWithDuration(float duration, const Vec2& deltaPosition);
  549. bool initWithDuration(float duration, const Vec3& deltaPosition);
  550. protected:
  551. bool _is3D;
  552. Vec3 _positionDelta;
  553. Vec3 _startPosition;
  554. Vec3 _previousPosition;
  555. private:
  556. CC_DISALLOW_COPY_AND_ASSIGN(MoveBy);
  557. };
  558. /** @class MoveTo
  559. * @brief Moves a Node object to the position x,y. x and y are absolute coordinates by modifying it's position attribute.
  560. Several MoveTo actions can be concurrently called, and the resulting
  561. movement will be the sum of individual movements.
  562. @since v2.1beta2-custom
  563. */
  564. class CC_DLL MoveTo : public MoveBy
  565. {
  566. public:
  567. /**
  568. * Creates the action.
  569. * @param duration Duration time, in seconds.
  570. * @param position The destination position in 2d.
  571. * @return An autoreleased MoveTo object.
  572. */
  573. static MoveTo* create(float duration, const Vec2& position);
  574. /**
  575. * Creates the action.
  576. * @param duration Duration time, in seconds.
  577. * @param position The destination position in 3d.
  578. * @return An autoreleased MoveTo object.
  579. */
  580. static MoveTo* create(float duration, const Vec3& position);
  581. //
  582. // Overrides
  583. //
  584. virtual MoveTo* clone() const override;
  585. virtual MoveTo* reverse() const override;
  586. virtual void startWithTarget(Node *target) override;
  587. CC_CONSTRUCTOR_ACCESS:
  588. MoveTo() {}
  589. virtual ~MoveTo() {}
  590. /**
  591. * initializes the action
  592. * @param duration in seconds
  593. */
  594. bool initWithDuration(float duration, const Vec2& position);
  595. /**
  596. * initializes the action
  597. * @param duration in seconds
  598. */
  599. bool initWithDuration(float duration, const Vec3& position);
  600. protected:
  601. Vec3 _endPosition;
  602. private:
  603. CC_DISALLOW_COPY_AND_ASSIGN(MoveTo);
  604. };
  605. /** @class SkewTo
  606. * @brief Skews a Node object to given angles by modifying it's skewX and skewY attributes
  607. @since v1.0
  608. */
  609. class CC_DLL SkewTo : public ActionInterval
  610. {
  611. public:
  612. /**
  613. * Creates the action.
  614. * @param t Duration time, in seconds.
  615. * @param sx Skew x angle.
  616. * @param sy Skew y angle.
  617. * @return An autoreleased SkewTo object.
  618. */
  619. static SkewTo* create(float t, float sx, float sy);
  620. //
  621. // Overrides
  622. //
  623. virtual SkewTo* clone() const override;
  624. virtual SkewTo* reverse() const override;
  625. virtual void startWithTarget(Node *target) override;
  626. /**
  627. * @param time In seconds.
  628. */
  629. virtual void update(float time) override;
  630. CC_CONSTRUCTOR_ACCESS:
  631. SkewTo();
  632. virtual ~SkewTo() {}
  633. /**
  634. * @param t In seconds.
  635. */
  636. bool initWithDuration(float t, float sx, float sy);
  637. protected:
  638. float _skewX;
  639. float _skewY;
  640. float _startSkewX;
  641. float _startSkewY;
  642. float _endSkewX;
  643. float _endSkewY;
  644. float _deltaX;
  645. float _deltaY;
  646. private:
  647. CC_DISALLOW_COPY_AND_ASSIGN(SkewTo);
  648. };
  649. /** @class SkewBy
  650. * @brief Skews a Node object by skewX and skewY degrees.
  651. @since v1.0
  652. */
  653. class CC_DLL SkewBy : public SkewTo
  654. {
  655. public:
  656. /**
  657. * Creates the action.
  658. * @param t Duration time, in seconds.
  659. * @param deltaSkewX Skew x delta angle.
  660. * @param deltaSkewY Skew y delta angle.
  661. * @return An autoreleased SkewBy object.
  662. */
  663. static SkewBy* create(float t, float deltaSkewX, float deltaSkewY);
  664. //
  665. // Overrides
  666. //
  667. virtual void startWithTarget(Node *target) override;
  668. virtual SkewBy* clone() const override;
  669. virtual SkewBy* reverse() const override;
  670. CC_CONSTRUCTOR_ACCESS:
  671. SkewBy() {}
  672. virtual ~SkewBy() {}
  673. /**
  674. * @param t In seconds.
  675. */
  676. bool initWithDuration(float t, float sx, float sy);
  677. private:
  678. CC_DISALLOW_COPY_AND_ASSIGN(SkewBy);
  679. };
  680. /** @class ResizeTo
  681. * @brief Resize a Node object to the final size by modifying it's Size attribute.
  682. */
  683. class CC_DLL ResizeTo : public ActionInterval
  684. {
  685. public:
  686. /**
  687. * Creates the action.
  688. * @brief Resize a Node object to the final size by modifying it's Size attribute. Works on all nodes where setContentSize is effective. But it's mostly useful for nodes where 9-slice is enabled
  689. * @param duration Duration time, in seconds.
  690. * @param final_size The target size to reach
  691. * @return An autoreleased RotateTo object.
  692. */
  693. static ResizeTo* create(float duration, const cocos2d::Size& final_size);
  694. //
  695. // Overrides
  696. //
  697. virtual ResizeTo* clone() const override;
  698. void startWithTarget(cocos2d::Node* target) override;
  699. void update(float time) override;
  700. CC_CONSTRUCTOR_ACCESS:
  701. ResizeTo() {}
  702. virtual ~ResizeTo() {}
  703. /**
  704. * initializes the action
  705. * @param duration in seconds
  706. * @param final_size in Size type
  707. */
  708. bool initWithDuration(float duration, const cocos2d::Size& final_size);
  709. protected:
  710. cocos2d::Size _initialSize;
  711. cocos2d::Size _finalSize;
  712. cocos2d::Size _sizeDelta;
  713. private:
  714. CC_DISALLOW_COPY_AND_ASSIGN(ResizeTo);
  715. };
  716. /** @class ResizeBy
  717. * @brief Resize a Node object by a Size. Works on all nodes where setContentSize is effective. But it's mostly useful for nodes where 9-slice is enabled
  718. */
  719. class CC_DLL ResizeBy : public ActionInterval
  720. {
  721. public:
  722. /**
  723. * Creates the action.
  724. *
  725. * @param duration Duration time, in seconds.
  726. * @param deltaSize The delta size.
  727. * @return An autoreleased ResizeBy object.
  728. */
  729. static ResizeBy* create(float duration, const cocos2d::Size& deltaSize);
  730. //
  731. // Overrides
  732. //
  733. virtual ResizeBy* clone() const override;
  734. virtual ResizeBy* reverse() const override;
  735. virtual void startWithTarget(Node *target) override;
  736. /**
  737. * @param time in seconds
  738. */
  739. virtual void update(float time) override;
  740. CC_CONSTRUCTOR_ACCESS:
  741. ResizeBy() {}
  742. virtual ~ResizeBy() {}
  743. /** initializes the action */
  744. bool initWithDuration(float duration, const cocos2d::Size& deltaSize);
  745. protected:
  746. cocos2d::Size _sizeDelta;
  747. cocos2d::Size _startSize;
  748. cocos2d::Size _previousSize;
  749. private:
  750. CC_DISALLOW_COPY_AND_ASSIGN(ResizeBy);
  751. };
  752. /** @class JumpBy
  753. * @brief Moves a Node object simulating a parabolic jump movement by modifying it's position attribute.
  754. */
  755. class CC_DLL JumpBy : public ActionInterval
  756. {
  757. public:
  758. /**
  759. * Creates the action.
  760. * @param duration Duration time, in seconds.
  761. * @param position The jumping distance.
  762. * @param height The jumping height.
  763. * @param jumps The jumping times.
  764. * @return An autoreleased JumpBy object.
  765. */
  766. static JumpBy* create(float duration, const Vec2& position, float height, int jumps);
  767. //
  768. // Overrides
  769. //
  770. virtual JumpBy* clone() const override;
  771. virtual JumpBy* reverse() const override;
  772. virtual void startWithTarget(Node *target) override;
  773. /**
  774. * @param time In seconds.
  775. */
  776. virtual void update(float time) override;
  777. CC_CONSTRUCTOR_ACCESS:
  778. JumpBy() {}
  779. virtual ~JumpBy() {}
  780. /**
  781. * initializes the action
  782. * @param duration in seconds
  783. */
  784. bool initWithDuration(float duration, const Vec2& position, float height, int jumps);
  785. protected:
  786. Vec2 _startPosition;
  787. Vec2 _delta;
  788. float _height;
  789. int _jumps;
  790. Vec2 _previousPos;
  791. private:
  792. CC_DISALLOW_COPY_AND_ASSIGN(JumpBy);
  793. };
  794. /** @class JumpTo
  795. * @brief Moves a Node object to a parabolic position simulating a jump movement by modifying it's position attribute.
  796. */
  797. class CC_DLL JumpTo : public JumpBy
  798. {
  799. public:
  800. /**
  801. * Creates the action.
  802. * @param duration Duration time, in seconds.
  803. * @param position The jumping destination position.
  804. * @param height The jumping height.
  805. * @param jumps The jumping times.
  806. * @return An autoreleased JumpTo object.
  807. */
  808. static JumpTo* create(float duration, const Vec2& position, float height, int jumps);
  809. //
  810. // Override
  811. //
  812. virtual void startWithTarget(Node *target) override;
  813. virtual JumpTo* clone() const override;
  814. virtual JumpTo* reverse() const override;
  815. CC_CONSTRUCTOR_ACCESS:
  816. JumpTo() {}
  817. virtual ~JumpTo() {}
  818. /**
  819. * initializes the action
  820. * @param duration In seconds.
  821. */
  822. bool initWithDuration(float duration, const Vec2& position, float height, int jumps);
  823. protected:
  824. Vec2 _endPosition;
  825. private:
  826. CC_DISALLOW_COPY_AND_ASSIGN(JumpTo);
  827. };
  828. /** @struct Bezier configuration structure
  829. */
  830. typedef struct _ccBezierConfig {
  831. //! end position of the bezier
  832. Vec2 endPosition;
  833. //! control point number
  834. int num_control_point;
  835. //! Bezier control point 1
  836. Vec2 controlPoint_1;
  837. //! Bezier control point 2
  838. Vec2 controlPoint_2;
  839. //! Bezier control point 3
  840. Vec2 controlPoint_3;
  841. _ccBezierConfig() {
  842. num_control_point = 2;
  843. }
  844. } ccBezierConfig;
  845. /** @class BezierBy
  846. * @brief An action that moves the target with a cubic Bezier curve by a certain distance.
  847. */
  848. class CC_DLL BezierBy : public ActionInterval
  849. {
  850. public:
  851. /** Creates the action with a duration and a bezier configuration.
  852. * @param t Duration time, in seconds.
  853. * @param c Bezier config.
  854. * @return An autoreleased BezierBy object.
  855. * @code
  856. * When this function bound to js or lua,the input params are changed.
  857. * in js: var create(var t,var table)
  858. * in lua: local create(local t, local table)
  859. * @endcode
  860. */
  861. static BezierBy* create(float t, const ccBezierConfig& c);
  862. //
  863. // Overrides
  864. //
  865. virtual BezierBy* clone() const override;
  866. virtual BezierBy* reverse() const override;
  867. virtual void startWithTarget(Node *target) override;
  868. /**
  869. * @param time In seconds.
  870. */
  871. virtual void update(float time) override;
  872. CC_CONSTRUCTOR_ACCESS:
  873. BezierBy() {}
  874. virtual ~BezierBy() {}
  875. /**
  876. * initializes the action with a duration and a bezier configuration
  877. * @param t in seconds
  878. */
  879. bool initWithDuration(float t, const ccBezierConfig& c);
  880. protected:
  881. ccBezierConfig _config;
  882. Vec2 _startPosition;
  883. Vec2 _previousPosition;
  884. private:
  885. CC_DISALLOW_COPY_AND_ASSIGN(BezierBy);
  886. };
  887. /** @class BezierTo
  888. * @brief An action that moves the target with a cubic Bezier curve to a destination point.
  889. @since v0.8.2
  890. */
  891. class CC_DLL BezierTo : public BezierBy
  892. {
  893. public:
  894. /** Creates the action with a duration and a bezier configuration.
  895. * @param t Duration time, in seconds.
  896. * @param c Bezier config.
  897. * @return An autoreleased BezierTo object.
  898. * @code
  899. * when this function bound to js or lua,the input params are changed
  900. * in js: var create(var t,var table)
  901. * in lua: local create(local t, local table)
  902. * @endcode
  903. */
  904. static BezierTo* create(float t, const ccBezierConfig& c);
  905. //
  906. // Overrides
  907. //
  908. virtual void startWithTarget(Node *target) override;
  909. virtual BezierTo* clone() const override;
  910. virtual BezierTo* reverse() const override;
  911. CC_CONSTRUCTOR_ACCESS:
  912. BezierTo() {}
  913. virtual ~BezierTo() {}
  914. /**
  915. * @param t In seconds.
  916. */
  917. bool initWithDuration(float t, const ccBezierConfig &c);
  918. protected:
  919. ccBezierConfig _toConfig;
  920. private:
  921. CC_DISALLOW_COPY_AND_ASSIGN(BezierTo);
  922. };
  923. /** @class ScaleTo
  924. @brief Scales a Node object to a zoom factor by modifying it's scale attribute.
  925. @warning This action doesn't support "reverse".
  926. @warning The physics body contained in Node doesn't support this action.
  927. */
  928. class CC_DLL ScaleTo : public ActionInterval
  929. {
  930. public:
  931. /**
  932. * Creates the action with the same scale factor for X and Y.
  933. * @param duration Duration time, in seconds.
  934. * @param s Scale factor of x and y.
  935. * @return An autoreleased ScaleTo object.
  936. */
  937. static ScaleTo* create(float duration, float s);
  938. /**
  939. * Creates the action with and X factor and a Y factor.
  940. * @param duration Duration time, in seconds.
  941. * @param sx Scale factor of x.
  942. * @param sy Scale factor of y.
  943. * @return An autoreleased ScaleTo object.
  944. */
  945. static ScaleTo* create(float duration, float sx, float sy);
  946. /**
  947. * Creates the action with X Y Z factor.
  948. * @param duration Duration time, in seconds.
  949. * @param sx Scale factor of x.
  950. * @param sy Scale factor of y.
  951. * @param sz Scale factor of z.
  952. * @return An autoreleased ScaleTo object.
  953. */
  954. static ScaleTo* create(float duration, float sx, float sy, float sz);
  955. //
  956. // Overrides
  957. //
  958. virtual ScaleTo* clone() const override;
  959. virtual ScaleTo* reverse() const override;
  960. virtual void startWithTarget(Node *target) override;
  961. /**
  962. * @param time In seconds.
  963. */
  964. virtual void update(float time) override;
  965. CC_CONSTRUCTOR_ACCESS:
  966. ScaleTo() {}
  967. virtual ~ScaleTo() {}
  968. /**
  969. * initializes the action with the same scale factor for X and Y
  970. * @param duration in seconds
  971. */
  972. bool initWithDuration(float duration, float s);
  973. /**
  974. * initializes the action with and X factor and a Y factor
  975. * @param duration in seconds
  976. */
  977. bool initWithDuration(float duration, float sx, float sy);
  978. /**
  979. * initializes the action with X Y Z factor
  980. * @param duration in seconds
  981. */
  982. bool initWithDuration(float duration, float sx, float sy, float sz);
  983. protected:
  984. float _scaleX;
  985. float _scaleY;
  986. float _scaleZ;
  987. float _startScaleX;
  988. float _startScaleY;
  989. float _startScaleZ;
  990. float _endScaleX;
  991. float _endScaleY;
  992. float _endScaleZ;
  993. float _deltaX;
  994. float _deltaY;
  995. float _deltaZ;
  996. private:
  997. CC_DISALLOW_COPY_AND_ASSIGN(ScaleTo);
  998. };
  999. /** @class ScaleBy
  1000. * @brief Scales a Node object a zoom factor by modifying it's scale attribute.
  1001. @warning The physics body contained in Node doesn't support this action.
  1002. */
  1003. class CC_DLL ScaleBy : public ScaleTo
  1004. {
  1005. public:
  1006. /**
  1007. * Creates the action with the same scale factor for X and Y.
  1008. * @param duration Duration time, in seconds.
  1009. * @param s Scale factor of x and y.
  1010. * @return An autoreleased ScaleBy object.
  1011. */
  1012. static ScaleBy* create(float duration, float s);
  1013. /**
  1014. * Creates the action with and X factor and a Y factor.
  1015. * @param duration Duration time, in seconds.
  1016. * @param sx Scale factor of x.
  1017. * @param sy Scale factor of y.
  1018. * @return An autoreleased ScaleBy object.
  1019. */
  1020. static ScaleBy* create(float duration, float sx, float sy);
  1021. /**
  1022. * Creates the action with X Y Z factor.
  1023. * @param duration Duration time, in seconds.
  1024. * @param sx Scale factor of x.
  1025. * @param sy Scale factor of y.
  1026. * @param sz Scale factor of z.
  1027. * @return An autoreleased ScaleBy object.
  1028. */
  1029. static ScaleBy* create(float duration, float sx, float sy, float sz);
  1030. //
  1031. // Overrides
  1032. //
  1033. virtual void startWithTarget(Node *target) override;
  1034. virtual ScaleBy* clone() const override;
  1035. virtual ScaleBy* reverse() const override;
  1036. CC_CONSTRUCTOR_ACCESS:
  1037. ScaleBy() {}
  1038. virtual ~ScaleBy() {}
  1039. private:
  1040. CC_DISALLOW_COPY_AND_ASSIGN(ScaleBy);
  1041. };
  1042. /** @class Blink
  1043. * @brief Blinks a Node object by modifying it's visible attribute.
  1044. */
  1045. class CC_DLL Blink : public ActionInterval
  1046. {
  1047. public:
  1048. /**
  1049. * Creates the action.
  1050. * @param duration Duration time, in seconds.
  1051. * @param blinks Blink times.
  1052. * @return An autoreleased Blink object.
  1053. */
  1054. static Blink* create(float duration, int blinks);
  1055. //
  1056. // Overrides
  1057. //
  1058. virtual Blink* clone() const override;
  1059. virtual Blink* reverse() const override;
  1060. /**
  1061. * @param time In seconds.
  1062. */
  1063. virtual void update(float time) override;
  1064. virtual void startWithTarget(Node *target) override;
  1065. virtual void stop() override;
  1066. CC_CONSTRUCTOR_ACCESS:
  1067. Blink() {}
  1068. virtual ~Blink() {}
  1069. /**
  1070. * initializes the action
  1071. * @param duration in seconds
  1072. */
  1073. bool initWithDuration(float duration, int blinks);
  1074. protected:
  1075. int _times;
  1076. bool _originalState;
  1077. private:
  1078. CC_DISALLOW_COPY_AND_ASSIGN(Blink);
  1079. };
  1080. /** @class FadeTo
  1081. * @brief Fades an object that implements the RGBAProtocol protocol. It modifies the opacity from the current value to a custom one.
  1082. @warning This action doesn't support "reverse"
  1083. */
  1084. class CC_DLL FadeTo : public ActionInterval
  1085. {
  1086. public:
  1087. /**
  1088. * Creates an action with duration and opacity.
  1089. * @param duration Duration time, in seconds.
  1090. * @param opacity A certain opacity, the range is from 0 to 255.
  1091. * @return An autoreleased FadeTo object.
  1092. */
  1093. static FadeTo* create(float duration, GLubyte opacity);
  1094. //
  1095. // Overrides
  1096. //
  1097. virtual FadeTo* clone() const override;
  1098. virtual FadeTo* reverse() const override;
  1099. virtual void startWithTarget(Node *target) override;
  1100. /**
  1101. * @param time In seconds.
  1102. */
  1103. virtual void update(float time) override;
  1104. CC_CONSTRUCTOR_ACCESS:
  1105. FadeTo() {}
  1106. virtual ~FadeTo() {}
  1107. /**
  1108. * initializes the action with duration and opacity
  1109. * @param duration in seconds
  1110. */
  1111. bool initWithDuration(float duration, GLubyte opacity);
  1112. protected:
  1113. GLubyte _toOpacity;
  1114. GLubyte _fromOpacity;
  1115. friend class FadeOut;
  1116. friend class FadeIn;
  1117. private:
  1118. CC_DISALLOW_COPY_AND_ASSIGN(FadeTo);
  1119. };
  1120. /** @class FadeIn
  1121. * @brief Fades In an object that implements the RGBAProtocol protocol. It modifies the opacity from 0 to 255.
  1122. The "reverse" of this action is FadeOut
  1123. */
  1124. class CC_DLL FadeIn : public FadeTo
  1125. {
  1126. public:
  1127. /**
  1128. * Creates the action.
  1129. * @param d Duration time, in seconds.
  1130. * @return An autoreleased FadeIn object.
  1131. */
  1132. static FadeIn* create(float d);
  1133. //
  1134. // Overrides
  1135. //
  1136. virtual void startWithTarget(Node *target) override;
  1137. virtual FadeIn* clone() const override;
  1138. virtual FadeTo* reverse() const override;
  1139. /**
  1140. * @js NA
  1141. */
  1142. void setReverseAction(FadeTo* ac);
  1143. CC_CONSTRUCTOR_ACCESS:
  1144. FadeIn():_reverseAction(nullptr) {}
  1145. virtual ~FadeIn() {}
  1146. private:
  1147. CC_DISALLOW_COPY_AND_ASSIGN(FadeIn);
  1148. FadeTo* _reverseAction;
  1149. };
  1150. /** @class FadeOut
  1151. * @brief Fades Out an object that implements the RGBAProtocol protocol. It modifies the opacity from 255 to 0.
  1152. The "reverse" of this action is FadeIn
  1153. */
  1154. class CC_DLL FadeOut : public FadeTo
  1155. {
  1156. public:
  1157. /**
  1158. * Creates the action.
  1159. * @param d Duration time, in seconds.
  1160. */
  1161. static FadeOut* create(float d);
  1162. //
  1163. // Overrides
  1164. //
  1165. virtual void startWithTarget(Node *target) override;
  1166. virtual FadeOut* clone() const override;
  1167. virtual FadeTo* reverse() const override;
  1168. /**
  1169. * @js NA
  1170. */
  1171. void setReverseAction(FadeTo* ac);
  1172. CC_CONSTRUCTOR_ACCESS:
  1173. FadeOut():_reverseAction(nullptr) {}
  1174. virtual ~FadeOut() {}
  1175. private:
  1176. CC_DISALLOW_COPY_AND_ASSIGN(FadeOut);
  1177. FadeTo* _reverseAction;
  1178. };
  1179. /** @class TintTo
  1180. * @brief Tints a Node that implements the NodeRGB protocol from current tint to a custom one.
  1181. @warning This action doesn't support "reverse"
  1182. @since v0.7.2
  1183. */
  1184. class CC_DLL TintTo : public ActionInterval
  1185. {
  1186. public:
  1187. /**
  1188. * Creates an action with duration and color.
  1189. * @param duration Duration time, in seconds.
  1190. * @param red Red Color, from 0 to 255.
  1191. * @param green Green Color, from 0 to 255.
  1192. * @param blue Blue Color, from 0 to 255.
  1193. * @return An autoreleased TintTo object.
  1194. */
  1195. static TintTo* create(float duration, GLubyte red, GLubyte green, GLubyte blue);
  1196. /**
  1197. * Creates an action with duration and color.
  1198. * @param duration Duration time, in seconds.
  1199. * @param color It's a Color3B type.
  1200. * @return An autoreleased TintTo object.
  1201. */
  1202. static TintTo* create(float duration, const Color3B& color);
  1203. //
  1204. // Overrides
  1205. //
  1206. virtual TintTo* clone() const override;
  1207. virtual TintTo* reverse() const override;
  1208. virtual void startWithTarget(Node *target) override;
  1209. /**
  1210. * @param time In seconds.
  1211. */
  1212. virtual void update(float time) override;
  1213. CC_CONSTRUCTOR_ACCESS:
  1214. TintTo() {}
  1215. virtual ~TintTo() {}
  1216. /** initializes the action with duration and color */
  1217. bool initWithDuration(float duration, GLubyte red, GLubyte green, GLubyte blue);
  1218. protected:
  1219. Color3B _to;
  1220. Color3B _from;
  1221. private:
  1222. CC_DISALLOW_COPY_AND_ASSIGN(TintTo);
  1223. };
  1224. /** @class TintBy
  1225. @brief Tints a Node that implements the NodeRGB protocol from current tint to a custom one.
  1226. @since v0.7.2
  1227. */
  1228. class CC_DLL TintBy : public ActionInterval
  1229. {
  1230. public:
  1231. /**
  1232. * Creates an action with duration and color.
  1233. * @param duration Duration time, in seconds.
  1234. * @param deltaRed Delta red color.
  1235. * @param deltaGreen Delta green color.
  1236. * @param deltaBlue Delta blue color.
  1237. * @return An autoreleased TintBy object.
  1238. */
  1239. static TintBy* create(float duration, GLshort deltaRed, GLshort deltaGreen, GLshort deltaBlue);
  1240. //
  1241. // Overrides
  1242. //
  1243. virtual TintBy* clone() const override;
  1244. virtual TintBy* reverse() const override;
  1245. virtual void startWithTarget(Node *target) override;
  1246. /**
  1247. * @param time In seconds.
  1248. */
  1249. virtual void update(float time) override;
  1250. CC_CONSTRUCTOR_ACCESS:
  1251. TintBy() {}
  1252. virtual ~TintBy() {}
  1253. /** initializes the action with duration and color */
  1254. bool initWithDuration(float duration, GLshort deltaRed, GLshort deltaGreen, GLshort deltaBlue);
  1255. protected:
  1256. GLshort _deltaR;
  1257. GLshort _deltaG;
  1258. GLshort _deltaB;
  1259. GLshort _fromR;
  1260. GLshort _fromG;
  1261. GLshort _fromB;
  1262. private:
  1263. CC_DISALLOW_COPY_AND_ASSIGN(TintBy);
  1264. };
  1265. /** @class DelayTime
  1266. * @brief Delays the action a certain amount of seconds.
  1267. */
  1268. class CC_DLL DelayTime : public ActionInterval
  1269. {
  1270. public:
  1271. /**
  1272. * Creates the action.
  1273. * @param d Duration time, in seconds.
  1274. * @return An autoreleased DelayTime object.
  1275. */
  1276. static DelayTime* create(float d);
  1277. //
  1278. // Overrides
  1279. //
  1280. /**
  1281. * @param time In seconds.
  1282. */
  1283. virtual void update(float time) override;
  1284. virtual DelayTime* reverse() const override;
  1285. virtual DelayTime* clone() const override;
  1286. CC_CONSTRUCTOR_ACCESS:
  1287. DelayTime() {}
  1288. virtual ~DelayTime() {}
  1289. private:
  1290. CC_DISALLOW_COPY_AND_ASSIGN(DelayTime);
  1291. };
  1292. /** @class ReverseTime
  1293. * @brief Executes an action in reverse order, from time=duration to time=0
  1294. @warning Use this action carefully. This action is not
  1295. sequenceable. Use it as the default "reversed" method
  1296. of your own actions, but using it outside the "reversed"
  1297. scope is not recommended.
  1298. */
  1299. class CC_DLL ReverseTime : public ActionInterval
  1300. {
  1301. public:
  1302. /** Creates the action.
  1303. *
  1304. * @param action a certain action.
  1305. * @return An autoreleased ReverseTime object.
  1306. */
  1307. static ReverseTime* create(FiniteTimeAction *action);
  1308. //
  1309. // Overrides
  1310. //
  1311. virtual ReverseTime* reverse() const override;
  1312. virtual ReverseTime* clone() const override;
  1313. virtual void startWithTarget(Node *target) override;
  1314. virtual void stop() override;
  1315. /**
  1316. * @param time In seconds.
  1317. */
  1318. virtual void update(float time) override;
  1319. CC_CONSTRUCTOR_ACCESS:
  1320. ReverseTime();
  1321. virtual ~ReverseTime();
  1322. /** initializes the action */
  1323. bool initWithAction(FiniteTimeAction *action);
  1324. protected:
  1325. FiniteTimeAction *_other;
  1326. private:
  1327. CC_DISALLOW_COPY_AND_ASSIGN(ReverseTime);
  1328. };
  1329. class Texture2D;
  1330. /** @class Animate
  1331. * @brief Animates a sprite given the name of an Animation.
  1332. */
  1333. class CC_DLL Animate : public ActionInterval
  1334. {
  1335. public:
  1336. /** Creates the action with an Animation and will restore the original frame when the animation is over.
  1337. *
  1338. * @param animation A certain animation.
  1339. * @return An autoreleased Animate object.
  1340. */
  1341. static Animate* create(Animation *animation);
  1342. /** Sets the Animation object to be animated
  1343. *
  1344. * @param animation certain animation.
  1345. */
  1346. void setAnimation( Animation* animation );
  1347. /** returns the Animation object that is being animated
  1348. *
  1349. * @return Gets the animation object that is being animated.
  1350. */
  1351. Animation* getAnimation() { return _animation; }
  1352. const Animation* getAnimation() const { return _animation; }
  1353. /**
  1354. * Gets the index of sprite frame currently displayed.
  1355. * @return int the index of sprite frame currently displayed.
  1356. */
  1357. int getCurrentFrameIndex() { return _currFrameIndex; }
  1358. //
  1359. // Overrides
  1360. //
  1361. virtual Animate* clone() const override;
  1362. virtual Animate* reverse() const override;
  1363. virtual void startWithTarget(Node *target) override;
  1364. virtual void stop() override;
  1365. /**
  1366. * @param t In seconds.
  1367. */
  1368. virtual void update(float t) override;
  1369. CC_CONSTRUCTOR_ACCESS:
  1370. Animate();
  1371. virtual ~Animate();
  1372. /** initializes the action with an Animation and will restore the original frame when the animation is over */
  1373. bool initWithAnimation(Animation *animation);
  1374. protected:
  1375. std::vector<float>* _splitTimes;
  1376. int _nextFrame;
  1377. SpriteFrame* _origFrame;
  1378. int _currFrameIndex;
  1379. unsigned int _executedLoops;
  1380. Animation* _animation;
  1381. EventCustom* _frameDisplayedEvent;
  1382. AnimationFrame::DisplayedEventInfo _frameDisplayedEventInfo;
  1383. private:
  1384. CC_DISALLOW_COPY_AND_ASSIGN(Animate);
  1385. };
  1386. /** @class TargetedAction
  1387. * @brief Overrides the target of an action so that it always runs on the target
  1388. * specified at action creation rather than the one specified by runAction.
  1389. */
  1390. class CC_DLL TargetedAction : public ActionInterval
  1391. {
  1392. public:
  1393. /** Create an action with the specified action and forced target.
  1394. *
  1395. * @param target The target needs to override.
  1396. * @param action The action needs to override.
  1397. * @return An autoreleased TargetedAction object.
  1398. */
  1399. static TargetedAction* create(Node* target, FiniteTimeAction* action);
  1400. /** Sets the target that the action will be forced to run with.
  1401. *
  1402. * @param forcedTarget The target that the action will be forced to run with.
  1403. */
  1404. void setForcedTarget(Node* forcedTarget);
  1405. /** returns the target that the action is forced to run with.
  1406. *
  1407. * @return The target that the action is forced to run with.
  1408. */
  1409. Node* getForcedTarget() { return _forcedTarget; }
  1410. const Node* getForcedTarget() const { return _forcedTarget; }
  1411. //
  1412. // Overrides
  1413. //
  1414. virtual TargetedAction* clone() const override;
  1415. virtual TargetedAction* reverse() const override;
  1416. virtual void startWithTarget(Node *target) override;
  1417. virtual void stop() override;
  1418. /**
  1419. * @param time In seconds.
  1420. */
  1421. virtual void update(float time) override;
  1422. CC_CONSTRUCTOR_ACCESS:
  1423. TargetedAction();
  1424. virtual ~TargetedAction();
  1425. /** Init an action with the specified action and forced target */
  1426. bool initWithTarget(Node* target, FiniteTimeAction* action);
  1427. protected:
  1428. FiniteTimeAction* _action;
  1429. Node* _forcedTarget;
  1430. private:
  1431. CC_DISALLOW_COPY_AND_ASSIGN(TargetedAction);
  1432. };
  1433. /**
  1434. * @class ActionFloat
  1435. * @brief Action used to animate any value in range [from,to] over specified time interval
  1436. */
  1437. class CC_DLL ActionFloat : public ActionInterval
  1438. {
  1439. public:
  1440. /**
  1441. * Callback function used to report back result
  1442. */
  1443. typedef std::function<void(float value)> ActionFloatCallback;
  1444. /**
  1445. * Creates FloatAction with specified duration, from value, to value and callback to report back
  1446. * results
  1447. * @param duration of the action
  1448. * @param from value to start from
  1449. * @param to value to be at the end of the action
  1450. * @param callback to report back result
  1451. *
  1452. * @return An autoreleased ActionFloat object
  1453. */
  1454. static ActionFloat* create(float duration, float from, float to, ActionFloatCallback callback);
  1455. /**
  1456. * Overridden ActionInterval methods
  1457. */
  1458. void startWithTarget(Node* target) override;
  1459. void update(float delta) override;
  1460. ActionFloat* reverse() const override;
  1461. ActionFloat* clone() const override;
  1462. CC_CONSTRUCTOR_ACCESS:
  1463. ActionFloat() {};
  1464. virtual ~ActionFloat() {};
  1465. bool initWithDuration(float duration, float from, float to, ActionFloatCallback callback);
  1466. protected:
  1467. /* From value */
  1468. float _from;
  1469. /* To value */
  1470. float _to;
  1471. /* delta time */
  1472. float _delta;
  1473. /* Callback to report back results */
  1474. ActionFloatCallback _callback;
  1475. private:
  1476. CC_DISALLOW_COPY_AND_ASSIGN(ActionFloat);
  1477. };
  1478. // end of actions group
  1479. /// @}
  1480. NS_CC_END
  1481. #endif //__ACTION_CCINTERVAL_ACTION_H__