CCActionInterval.h 48 KB

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