CCActionInterval.h 48 KB

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