REDAnimationManager.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. #ifndef __RED_REDANIMATION_MANAGER_H__
  2. #define __RED_REDANIMATION_MANAGER_H__
  3. #include "base/CCMap.h"
  4. #include "2d/CCActionInterval.h"
  5. #include "2d/CCActionInstant.h"
  6. #include "2d/CCActionEase.h"
  7. #include "extensions/ExtensionMacros.h"
  8. #include "REDSequence.h"
  9. #include "REDKeyframe.h"
  10. #include "REDSequenceProperty.h"
  11. #include "extensions/GUI/CCControlExtension/CCControl.h"
  12. #include "2d/ZMLCCParticleSystem.h"
  13. #include "2d/ZMLCCParticleSystemQuad.h"
  14. #include "2d/ZGFrameActionSprite.h"
  15. #include "editor-support/spine/bake/RedBakeNode.h"
  16. #include <unordered_set>
  17. namespace redream {
  18. enum class AnimationCompleteType
  19. {
  20. CHAINED,
  21. COMPLETED,
  22. STOPED
  23. };
  24. #define RED_SEQ_COMPLETED_GLUE(SNAME, METHOD) if(strcmp(name, SNAME) == 0) { \
  25. if (METHOD) {METHOD(SNAME); return;} \
  26. }
  27. #define RED_SEQ_COMPLETED_AND_PLAY_NEXT_GLUE(SNAME, METHOD) if(strcmp(name, SNAME) == 0) { \
  28. if (METHOD) {METHOD(SNAME); return;} \
  29. }
  30. #define RED_SEQ_STOPPED_GLUE(SNAME, METHOD) if(strcmp(name, SNAME) == 0) { \
  31. if (METHOD) {METHOD(SNAME); return;} \
  32. }
  33. class CC_DLL REDAnimationManagerDelegate
  34. {
  35. public:
  36. virtual ~REDAnimationManagerDelegate() {}
  37. //完成的动画序列
  38. virtual void completedAnimationSequenceNamed(const char *name, int seqId, int tag) = 0;
  39. // 动画播完了但是会继续播放下一条动画
  40. virtual void completedAnimationAndPlayNextSequenceNamed(const char *name, int seqId, int tag){};
  41. // 动画被stop掉了
  42. virtual void stopAnimationSequenceNamed(const char *name, int seqId, int tag){};
  43. };
  44. class CC_DLL REDAnimationManager : public cocos2d::Ref
  45. {
  46. public:
  47. #pragma mark - Begin BatchNode
  48. ///add by songqingyu for BatchNode
  49. ///重新设置所有可能的sprite的displayFrame
  50. void resetSpriteFrameOfAllChildrenAnimtion();
  51. void addDisplayFrameKeykframe(REDKeyframe* kf);
  52. void addSpriteFrameForNode(cocos2d::Node* pNode,const std::string& propName,const std::string& spriteFile,const std::string& spriteSheet);
  53. void setREDRootPath(std::string redRootPath);
  54. /// 后面的方法(getSpriteFrameByName)需要知道查找的spriteframeName所在的plist
  55. /// @param plistSt 初始加载时需要从这个plist中查找
  56. /// @param replacePlistSt 合批之后需要从这个plist中查找
  57. void setReaderPlist(std::unordered_set<std::string> plistSt,std::unordered_set<std::string> replacePlistSt);
  58. cocos2d::SpriteFrame* getSpriteFrameByName(const std::string& spriteFile,const std::string& spriteSheet,bool useDefaultEmpty=true);
  59. const std::unordered_set<std::string>& getRepleacePlistSt(){return _repleacePlistSt;};
  60. private:
  61. cocos2d::Vector<REDKeyframe*> _needResetSpriteFrames;
  62. std::string _redRootPath;
  63. std::unordered_set<std::string> _readerPlistSt;
  64. std::unordered_set<std::string> _repleacePlistSt;
  65. std::unordered_map<cocos2d::Node*, std::unordered_map<std::string,std::vector<std::string>>> _needResetObjProps;
  66. ///end
  67. #pragma mark end BatchNode -
  68. public:
  69. // bool _jsControlled;
  70. /**
  71. * @js ctor
  72. */
  73. REDAnimationManager();
  74. /**
  75. * @js NA
  76. * @lua NA
  77. */
  78. ~REDAnimationManager();
  79. static REDAnimationManager *fromNode(cocos2d::Node *node);
  80. cocos2d::Ref *_owner;
  81. virtual bool init();
  82. cocos2d::Vector<REDSequence*>& getSequences();
  83. void setSequences(const cocos2d::Vector<REDSequence*>& seq);
  84. int getAutoPlaySequenceId();
  85. void setAutoPlaySequenceId(int autoPlaySequenceId);
  86. cocos2d::Node* getRootNode();
  87. void setRootNode(cocos2d::Node* pRootNode); // weak reference
  88. void addDocumentCallbackNode(cocos2d::Node *node);
  89. void addDocumentCallbackName(std::string name);
  90. void addDocumentCallbackControlEvents(cocos2d::extension::Control::EventType eventType);
  91. void addDocumentOutletNode(cocos2d::Node *node);
  92. void addDocumentOutletName(std::string name);
  93. void setDocumentControllerName(const std::string &name);
  94. std::string getDocumentControllerName();
  95. cocos2d::ValueVector& getDocumentCallbackNames();
  96. cocos2d::Vector<cocos2d::Node*>& getDocumentCallbackNodes();
  97. cocos2d::ValueVector& getDocumentCallbackControlEvents();
  98. cocos2d::ValueVector& getDocumentOutletNames();
  99. cocos2d::Vector<cocos2d::Node*>& getDocumentOutletNodes();
  100. std::string getLastCompletedSequenceName();
  101. cocos2d::ValueVector& getKeyframeCallbacks();
  102. const cocos2d::Size& getRootContainerSize();
  103. void setRootContainerSize(const cocos2d::Size &rootContainerSize);
  104. REDAnimationManagerDelegate* getDelegate();
  105. void setDelegate(REDAnimationManagerDelegate* pDelegate); // retain
  106. const char* getRunningSequenceName();
  107. const cocos2d::Size& getContainerSize(cocos2d::Node* pNode);
  108. void addNode(cocos2d::Node *pNode, const std::unordered_map<int, cocos2d::Map<std::string, REDSequenceProperty*>>& seq);
  109. void setBaseValue(const cocos2d::Value& value, cocos2d::Node *pNode, const std::string& propName);
  110. void setObject(cocos2d::Ref* obj, cocos2d::Node *pNode, const std::string& propName);
  111. void moveAnimationsFromNode(cocos2d::Node* fromNode, cocos2d::Node* toNode);
  112. /** @deprecated This interface will be deprecated sooner or later.*/
  113. CC_DEPRECATED_ATTRIBUTE void runAnimations(const char *pName, float fTweenDuration);
  114. /** @deprecated This interface will be deprecated sooner or later.*/
  115. CC_DEPRECATED_ATTRIBUTE void runAnimations(const char *pName);
  116. /** @deprecated This interface will be deprecated sooner or later.*/
  117. CC_DEPRECATED_ATTRIBUTE void runAnimations(int nSeqId, float fTweenDuraiton);
  118. void runAnimationsForSequenceNamedTweenDuration(const char *pName, float fTweenDuration, const std::function<void(cocos2d::Node*, AnimationCompleteType)> &callback = nullptr);
  119. void runAnimationsForSequenceNamed(const char *pName);
  120. void runAnimationsForSequenceIdTweenDuration(int nSeqId, float fTweenDuraiton, const std::function<void(cocos2d::Node*, AnimationCompleteType)> &callback = nullptr, REDAnimationManagerDelegate* listen = nullptr);
  121. void runAnimationsWithTag(int nSeqId, int tag);
  122. void runAnimationsWithListen(int nSeqId, REDAnimationManagerDelegate* listen);
  123. cocos2d::Spawn* getNodeAniByName(const char *pName,cocos2d::Node *pNode,cocos2d::Vec2 orginPos);
  124. /**
  125. * when this function bound to js ,the second param are callfunc_selector
  126. * @lua NA
  127. */
  128. void setAnimationCompletedCallback(cocos2d::Ref *target, cocos2d::SEL_CallFunc callbackFunc);
  129. void debug();
  130. /**
  131. * @js setCallFuncForJSCallbackNamed
  132. */
  133. void setCallFunc(cocos2d::CallFunc *callFunc, const std::string &callbackNamed);
  134. cocos2d::Sequence* actionForCallbackChannel(REDSequenceProperty* channel);
  135. cocos2d::Sequence* actionForSoundChannel(REDSequenceProperty* channel);
  136. cocos2d::Sequence* actionForWiseChannel(REDSequenceProperty* channel);
  137. // return -1 if timeline not exist
  138. int getSequenceId(const char* pSequenceName);
  139. // get timeline duration
  140. float getSequenceDuration(const char* pSequenceName);
  141. std::string getREDFileName();
  142. void setREDFileName(std::string filename);
  143. CC_SYNTHESIZE(float, _speed, AnimationSpeed);
  144. void updateSpeed(float speed);
  145. void refreshStatusOnFirstFream(int nSeqId, float fTweenDuraiton);
  146. // REDAnimationManagerDelegate* getDelegate();
  147. // void addListen(REDAnimationManagerDelegate* pDelegate); // retain
  148. // void removeListen(REDAnimationManagerDelegate* pDelegate);
  149. void stopAllNodeAction();
  150. private:
  151. void stopRootNodeAction(REDSequence* seq, std::function<void(cocos2d::Node*, AnimationCompleteType)> callback);
  152. const cocos2d::Value& getBaseValue(cocos2d::Node *pNode, const std::string& propName);
  153. Ref* getObject(cocos2d::Node *pNode, const std::string& propName);
  154. REDSequence* getSequence(int nSequenceId);
  155. cocos2d::ActionInterval* getAction(REDKeyframe *pKeyframe0, REDKeyframe *pKeyframe1, const std::string& propName, cocos2d::Node *pNode);
  156. void setAnimatedProperty(const std::string& propName, cocos2d::Node *pNode, const cocos2d::Value& value, Ref* obj, float fTweenDuration, bool isBaseValue);
  157. void setFirstFrame(cocos2d::Node *pNode, REDSequenceProperty *pSeqProp, float fTweenDuration);
  158. cocos2d::ActionInterval* getEaseAction(cocos2d::ActionInterval *pAction, REDKeyframe::EasingType easingType, float* fEasingOpt);
  159. void runAction(cocos2d::Node *pNode, REDSequenceProperty *pSeqProp, float fTweenDuration);
  160. void sequenceCompleted(const std::function<void(cocos2d::Node*, AnimationCompleteType)> &callback);
  161. void updateSpeed(float speed, cocos2d::Node* node);
  162. void resetAllChildrenAnimtion(int nSeqId, float fTweenDuration, bool isRunAction);
  163. private:
  164. cocos2d::Vector<REDSequence*> _sequences;
  165. std::unordered_map<cocos2d::Node*, std::unordered_map<int, cocos2d::Map<std::string, REDSequenceProperty*>>> _nodeSequences;
  166. std::unordered_map<cocos2d::Node*, std::unordered_map<std::string, cocos2d::Value>> _baseValues;
  167. std::unordered_map<cocos2d::Node*, std::unordered_map<std::string, cocos2d::Ref*>> _objects;
  168. int _autoPlaySequenceId;
  169. cocos2d::Node *_rootNode;
  170. cocos2d::Size _rootContainerSize;
  171. REDAnimationManagerDelegate *_delegate;
  172. // REDSequence *_runningSequence;
  173. std::pair<REDSequence*, std::function<void(cocos2d::Node*, AnimationCompleteType)>> _runningSequence;
  174. std::map<cocos2d::Node*, cocos2d::Vector<cocos2d::Action*>> _runningActions;
  175. cocos2d::ValueVector _documentOutletNames;
  176. cocos2d::Vector<cocos2d::Node*> _documentOutletNodes;
  177. cocos2d::ValueVector _documentCallbackNames;
  178. cocos2d::Vector<cocos2d::Node*> _documentCallbackNodes;
  179. cocos2d::ValueVector _documentCallbackControlEvents;
  180. cocos2d::ValueVector _keyframeCallbacks;
  181. cocos2d::Map<std::string, cocos2d::CallFunc*> _keyframeCallFuncs;
  182. std::string _documentControllerName;
  183. std::string _lastCompletedSequenceName;
  184. cocos2d::SEL_CallFunc _animationCompleteCallbackFunc;
  185. cocos2d::Ref *_target;
  186. std::string _ccbFileName;
  187. REDAnimationManagerDelegate *_listen;
  188. int _lastTag;
  189. int _nowTag;
  190. public:
  191. friend class RedreamAnim;
  192. };
  193. class CC_DLL REDSetSpriteFrame : public cocos2d::ActionInstant
  194. {
  195. public:
  196. /** creates a Place action with a position */
  197. static REDSetSpriteFrame* create(cocos2d::SpriteFrame *pSpriteFrame);
  198. /**
  199. * @js NA
  200. * @lua NA
  201. */
  202. ~REDSetSpriteFrame();
  203. bool initWithSpriteFrame(cocos2d::SpriteFrame *pSpriteFrame);
  204. // Overrides
  205. virtual void update(float time) override;
  206. virtual REDSetSpriteFrame* clone() const override;
  207. virtual REDSetSpriteFrame* reverse() const override;
  208. private:
  209. cocos2d::SpriteFrame *_spriteFrame;
  210. };
  211. class CC_DLL REDAnimation : public cocos2d::ActionInstant
  212. {
  213. public:
  214. /** creates a Place action with a position */
  215. static REDAnimation* create(int animationId);
  216. /**
  217. * @js NA
  218. * @lua NA
  219. */
  220. ~REDAnimation();
  221. bool initWithAnimationId(int animationId);
  222. // Overrides
  223. virtual void update(float time) override;
  224. virtual REDAnimation* clone() const override;
  225. virtual REDAnimation* reverse() const override;
  226. private:
  227. int _animationId;
  228. };
  229. class CC_DLL REDSoundEffect : public cocos2d::ActionInstant
  230. {
  231. public:
  232. static REDSoundEffect* actionWithSoundFile(const std::string &file, float pitch, float pan, float gain);
  233. /**
  234. * @js NA
  235. * @lua NA
  236. */
  237. ~REDSoundEffect();
  238. bool initWithSoundFile(const std::string &file, float pitch, float pan, float gain);
  239. // Overrides
  240. virtual void update(float time) override;
  241. virtual REDSoundEffect* clone() const override;
  242. virtual REDSoundEffect* reverse() const override;
  243. private:
  244. std::string _soundFile;
  245. float _pitch, _pan, _gain;
  246. };
  247. class CC_DLL REDWiseEffect : public cocos2d::ActionInstant {
  248. public:
  249. static REDWiseEffect* actionWithConfig(const std::string &btnFileName, const std::string &eventName, bool forcePostEvent, const ValueVector& params);
  250. ~REDWiseEffect();
  251. bool initWithConfig(const std::string &btnFileName, const std::string &eventName, bool forcePostEvent, const ValueVector& params);
  252. // Overrides
  253. virtual void update(float time) override;
  254. virtual REDWiseEffect* clone() const override;
  255. virtual REDWiseEffect* reverse() const override;
  256. private:
  257. std::string _btnFileName;
  258. std::string _eventName;
  259. bool _forcePostEvent;
  260. ValueVector _params;
  261. };
  262. class CC_DLL REDLabelString : public cocos2d::ActionInstant
  263. {
  264. public:
  265. static REDLabelString* actionWithText(const std::string &text);
  266. /**
  267. * @js NA
  268. * @lua NA
  269. */
  270. ~REDLabelString();
  271. bool initWithText(const std::string &text);
  272. // Overrides
  273. virtual void update(float time) override;
  274. virtual REDLabelString* clone() const override;
  275. virtual REDLabelString* reverse() const override;
  276. private:
  277. std::string _text;
  278. };
  279. class CC_DLL REDRotateTo : public cocos2d::ActionInterval
  280. {
  281. public:
  282. static REDRotateTo* create(float fDuration, float fAngle);
  283. bool initWithDuration(float fDuration, float fAngle);
  284. // Override
  285. virtual void update(float time) override;
  286. virtual REDRotateTo* clone() const override;
  287. virtual REDRotateTo* reverse() const override;
  288. virtual void startWithTarget(cocos2d::Node *pNode) override;
  289. private:
  290. float _startAngle;
  291. float _dstAngle;
  292. float _diffAngle;
  293. };
  294. class CC_DLL REDRotateXTo: public cocos2d::ActionInterval
  295. {
  296. public:
  297. static REDRotateXTo* create(float fDuration, float fAngle);
  298. bool initWithDuration(float fDuration, float fAngle);
  299. // Overrides
  300. virtual void startWithTarget(cocos2d::Node *pNode) override;
  301. virtual REDRotateXTo* clone() const override;
  302. virtual REDRotateXTo* reverse() const override;
  303. virtual void update(float time) override;
  304. private:
  305. float _startAngle;
  306. float _dstAngle;
  307. float _diffAngle;
  308. };
  309. class CC_DLL REDRotateYTo: public cocos2d::ActionInterval
  310. {
  311. public:
  312. static REDRotateYTo* create(float fDuration, float fAngle);
  313. bool initWithDuration(float fDuration, float fAngle);
  314. // Override
  315. virtual void startWithTarget(cocos2d::Node *pNode) override;
  316. virtual REDRotateYTo* clone() const override;
  317. virtual REDRotateYTo* reverse() const override;
  318. virtual void update(float time) override;
  319. private:
  320. float _startAngle;
  321. float _dstAngle;
  322. float _diffAngle;
  323. };
  324. class CC_DLL REDFrameIndexTo : public cocos2d::ActionInterval {
  325. public:
  326. static REDFrameIndexTo* create(float fDuration, int startIndex, int endIndex);
  327. bool initWithDuration(float fDuration, int startIndex, int endIndex);
  328. // Override
  329. virtual void startWithTarget(cocos2d::Node *pNode) override;
  330. virtual REDFrameIndexTo* clone() const override;
  331. virtual REDFrameIndexTo* reverse() const override;
  332. virtual void update(float time) override;
  333. private:
  334. int _startIndex;
  335. int _endIndex;
  336. float _diffIndex;
  337. };
  338. // add zml 粒子属性动画
  339. // 粒子生成器尺寸
  340. class CC_DLL REDParticlePosVarTo : public cocos2d::ActionInterval {
  341. public:
  342. static REDParticlePosVarTo* create(float fDuration, cocos2d::Vec2 size);
  343. bool initWithDuration(float fDuration, cocos2d::Vec2 size);
  344. // Override
  345. virtual void startWithTarget(cocos2d::Node *pNode) override;
  346. virtual REDParticlePosVarTo* clone() const override;
  347. virtual REDParticlePosVarTo* reverse() const override;
  348. virtual void update(float time) override;
  349. private:
  350. cocos2d::Vec2 _startGravity;
  351. cocos2d::Vec2 _endGravity;
  352. cocos2d::Vec2 _diffGravity;
  353. };
  354. // 重力
  355. class CC_DLL REDGravityTo : public cocos2d::ActionInterval {
  356. public:
  357. static REDGravityTo* create(float fDuration, cocos2d::Vec2 gravity);
  358. bool initWithDuration(float fDuration, cocos2d::Vec2 gravity);
  359. // Override
  360. virtual void startWithTarget(cocos2d::Node *pNode) override;
  361. virtual REDGravityTo* clone() const override;
  362. virtual REDGravityTo* reverse() const override;
  363. virtual void update(float time) override;
  364. private:
  365. cocos2d::Vec2 _startGravity;
  366. cocos2d::Vec2 _endGravity;
  367. cocos2d::Vec2 _diffGravity;
  368. };
  369. //粒子速度
  370. class CC_DLL REDParticleSpeedTo : public cocos2d::ActionInterval {
  371. public:
  372. static REDParticleSpeedTo* create(float fDuration, cocos2d::Vec2 gravity);
  373. bool initWithDuration(float fDuration, cocos2d::Vec2 gravity);
  374. // Override
  375. virtual void startWithTarget(cocos2d::Node *pNode) override;
  376. virtual REDParticleSpeedTo* clone() const override;
  377. virtual REDParticleSpeedTo* reverse() const override;
  378. virtual void update(float time) override;
  379. private:
  380. cocos2d::Vec2 _startFloatVar;
  381. cocos2d::Vec2 _endFloatVar;
  382. cocos2d::Vec2 _diffFloatVar;
  383. };
  384. //粒子生命
  385. class CC_DLL REDParticleLifeTo : public cocos2d::ActionInterval {
  386. public:
  387. static REDParticleLifeTo* create(float fDuration, cocos2d::Vec2 gravity);
  388. bool initWithDuration(float fDuration, cocos2d::Vec2 gravity);
  389. // Override
  390. virtual void startWithTarget(cocos2d::Node *pNode) override;
  391. virtual REDParticleLifeTo* clone() const override;
  392. virtual REDParticleLifeTo* reverse() const override;
  393. virtual void update(float time) override;
  394. private:
  395. cocos2d::Vec2 _startFloatVar;
  396. cocos2d::Vec2 _endFloatVar;
  397. cocos2d::Vec2 _diffFloatVar;
  398. };
  399. //粒子开始大小
  400. class CC_DLL REDParticleStartSizeTo : public cocos2d::ActionInterval {
  401. public:
  402. static REDParticleStartSizeTo* create(float fDuration, cocos2d::Vec2 gravity);
  403. bool initWithDuration(float fDuration, cocos2d::Vec2 gravity);
  404. // Override
  405. virtual void startWithTarget(cocos2d::Node *pNode) override;
  406. virtual REDParticleStartSizeTo* clone() const override;
  407. virtual REDParticleStartSizeTo* reverse() const override;
  408. virtual void update(float time) override;
  409. private:
  410. cocos2d::Vec2 _startFloatVar;
  411. cocos2d::Vec2 _endFloatVar;
  412. cocos2d::Vec2 _diffFloatVar;
  413. };
  414. //粒子结束尺寸
  415. class CC_DLL REDParticleEndSizeTo : public cocos2d::ActionInterval {
  416. public:
  417. static REDParticleEndSizeTo* create(float fDuration, cocos2d::Vec2 floatVar);
  418. bool initWithDuration(float fDuration, cocos2d::Vec2 floatVar);
  419. // Override
  420. virtual void startWithTarget(cocos2d::Node *pNode) override;
  421. virtual REDParticleEndSizeTo* clone() const override;
  422. virtual REDParticleEndSizeTo* reverse() const override;
  423. virtual void update(float time) override;
  424. private:
  425. cocos2d::Vec2 _startFloatVar;
  426. cocos2d::Vec2 _endFloatVar;
  427. cocos2d::Vec2 _diffFloatVar;
  428. };
  429. //粒子开始旋转角度
  430. class CC_DLL REDParticleStartSpinTo : public cocos2d::ActionInterval {
  431. public:
  432. static REDParticleStartSpinTo* create(float fDuration, cocos2d::Vec2 floatVar);
  433. bool initWithDuration(float fDuration, cocos2d::Vec2 floatVar);
  434. // Override
  435. virtual void startWithTarget(cocos2d::Node *pNode) override;
  436. virtual REDParticleStartSpinTo* clone() const override;
  437. virtual REDParticleStartSpinTo* reverse() const override;
  438. virtual void update(float time) override;
  439. private:
  440. cocos2d::Vec2 _startFloatVar;
  441. cocos2d::Vec2 _endFloatVar;
  442. cocos2d::Vec2 _diffFloatVar;
  443. };
  444. //粒子结束旋转角度
  445. class CC_DLL REDParticleEndSpinTo : public cocos2d::ActionInterval {
  446. public:
  447. static REDParticleEndSpinTo* create(float fDuration, cocos2d::Vec2 floatVar);
  448. bool initWithDuration(float fDuration, cocos2d::Vec2 floatVar);
  449. // Override
  450. virtual void startWithTarget(cocos2d::Node *pNode) override;
  451. virtual REDParticleEndSpinTo* clone() const override;
  452. virtual REDParticleEndSpinTo* reverse() const override;
  453. virtual void update(float time) override;
  454. private:
  455. cocos2d::Vec2 _startFloatVar;
  456. cocos2d::Vec2 _endFloatVar;
  457. cocos2d::Vec2 _diffFloatVar;
  458. };
  459. //粒子发射角度
  460. class CC_DLL REDParticleAngleTo : public cocos2d::ActionInterval {
  461. public:
  462. static REDParticleAngleTo* create(float fDuration, cocos2d::Vec2 floatVar);
  463. bool initWithDuration(float fDuration, cocos2d::Vec2 floatVar);
  464. // Override
  465. virtual void startWithTarget(cocos2d::Node *pNode) override;
  466. virtual REDParticleAngleTo* clone() const override;
  467. virtual REDParticleAngleTo* reverse() const override;
  468. virtual void update(float time) override;
  469. private:
  470. cocos2d::Vec2 _startFloatVar;
  471. cocos2d::Vec2 _endFloatVar;
  472. cocos2d::Vec2 _diffFloatVar;
  473. };
  474. //粒子重力模式切向加速度
  475. class CC_DLL REDParticleTangentialAccelTo : public cocos2d::ActionInterval {
  476. public:
  477. static REDParticleTangentialAccelTo* create(float fDuration, cocos2d::Vec2 floatVar);
  478. bool initWithDuration(float fDuration, cocos2d::Vec2 floatVar);
  479. // Override
  480. virtual void startWithTarget(cocos2d::Node *pNode) override;
  481. virtual REDParticleTangentialAccelTo* clone() const override;
  482. virtual REDParticleTangentialAccelTo* reverse() const override;
  483. virtual void update(float time) override;
  484. private:
  485. cocos2d::Vec2 _startFloatVar;
  486. cocos2d::Vec2 _endFloatVar;
  487. cocos2d::Vec2 _diffFloatVar;
  488. };
  489. //粒子径向加速度
  490. class CC_DLL REDParticleRadialAccelTo : public cocos2d::ActionInterval {
  491. public:
  492. static REDParticleRadialAccelTo* create(float fDuration, cocos2d::Vec2 floatVar);
  493. bool initWithDuration(float fDuration, cocos2d::Vec2 floatVar);
  494. // Override
  495. virtual void startWithTarget(cocos2d::Node *pNode) override;
  496. virtual REDParticleRadialAccelTo* clone() const override;
  497. virtual REDParticleRadialAccelTo* reverse() const override;
  498. virtual void update(float time) override;
  499. private:
  500. cocos2d::Vec2 _startFloatVar;
  501. cocos2d::Vec2 _endFloatVar;
  502. cocos2d::Vec2 _diffFloatVar;
  503. };
  504. //粒子半径模式开始半径
  505. class CC_DLL REDParticleStartRadiusTo : public cocos2d::ActionInterval {
  506. public:
  507. static REDParticleStartRadiusTo* create(float fDuration, cocos2d::Vec2 floatVar);
  508. bool initWithDuration(float fDuration, cocos2d::Vec2 floatVar);
  509. // Override
  510. virtual void startWithTarget(cocos2d::Node *pNode) override;
  511. virtual REDParticleStartRadiusTo* clone() const override;
  512. virtual REDParticleStartRadiusTo* reverse() const override;
  513. virtual void update(float time) override;
  514. private:
  515. cocos2d::Vec2 _startFloatVar;
  516. cocos2d::Vec2 _endFloatVar;
  517. cocos2d::Vec2 _diffFloatVar;
  518. };
  519. //粒子半径模式结束半径
  520. class CC_DLL REDParticleEndRadiusTo : public cocos2d::ActionInterval {
  521. public:
  522. static REDParticleEndRadiusTo* create(float fDuration, cocos2d::Vec2 gravity);
  523. bool initWithDuration(float fDuration, cocos2d::Vec2 gravity);
  524. // Override
  525. virtual void startWithTarget(cocos2d::Node *pNode) override;
  526. virtual REDParticleEndRadiusTo* clone() const override;
  527. virtual REDParticleEndRadiusTo* reverse() const override;
  528. virtual void update(float time) override;
  529. private:
  530. cocos2d::Vec2 _startFloatVar;
  531. cocos2d::Vec2 _endFloatVar;
  532. cocos2d::Vec2 _diffFloatVar;
  533. };
  534. //粒子半径模式每秒旋转
  535. class CC_DLL REDParticleRotatePerSecondTo : public cocos2d::ActionInterval {
  536. public:
  537. static REDParticleRotatePerSecondTo* create(float fDuration, cocos2d::Vec2 gravity);
  538. bool initWithDuration(float fDuration, cocos2d::Vec2 gravity);
  539. // Override
  540. virtual void startWithTarget(cocos2d::Node *pNode) override;
  541. virtual REDParticleRotatePerSecondTo* clone() const override;
  542. virtual REDParticleRotatePerSecondTo* reverse() const override;
  543. virtual void update(float time) override;
  544. private:
  545. cocos2d::Vec2 _startFloatVar;
  546. cocos2d::Vec2 _endFloatVar;
  547. cocos2d::Vec2 _diffFloatVar;
  548. };
  549. class CC_DLL REDEaseInstant : public cocos2d::ActionEase
  550. {
  551. public:
  552. static REDEaseInstant* create(cocos2d::ActionInterval *pAction);
  553. virtual REDEaseInstant* clone() const override;
  554. virtual REDEaseInstant* reverse() const override;
  555. virtual void update(float dt) override;
  556. };
  557. /**
  558. @class EaseBezierByTimeAction
  559. @brief Ease Bezier
  560. @ingroup Actions
  561. */
  562. class CC_DLL EaseBezierByTimeAction : public cocos2d::ActionEase
  563. {
  564. public:
  565. /**
  566. @brief Create the action with the inner action.
  567. @param action The pointer of the inner action.
  568. @return A pointer of EaseBezierAction action. If creation failed, return nil.
  569. */
  570. static EaseBezierByTimeAction* create(cocos2d::ActionInterval* action);
  571. virtual void update(float time) override;
  572. virtual EaseBezierByTimeAction* clone() const override;
  573. virtual EaseBezierByTimeAction* reverse() const override;
  574. /**
  575. @brief Set the bezier parameters.
  576. */
  577. virtual void setBezierParamer( float p0, float p1, float p2, float p3);
  578. CC_CONSTRUCTOR_ACCESS:
  579. EaseBezierByTimeAction() {}
  580. virtual ~EaseBezierByTimeAction() {}
  581. protected:
  582. float _p0;
  583. float _p1;
  584. float _p2;
  585. float _p3;
  586. private:
  587. CC_DISALLOW_COPY_AND_ASSIGN(EaseBezierByTimeAction);
  588. };
  589. #pragma mark - RedBakeAnimationInstantAction
  590. class CC_DLL RedBakeAnimationInstantAction: public cocos2d::ActionInstant {
  591. public:
  592. static RedBakeAnimationInstantAction* create(const RedBakeNodeFrame& frame);
  593. bool init(const RedBakeNodeFrame& frame);
  594. virtual void update(float time) override;
  595. virtual RedBakeAnimationInstantAction* clone() const override;
  596. virtual RedBakeAnimationInstantAction* reverse() const override;
  597. private:
  598. RedBakeNodeFrame _bakeFrame;
  599. };
  600. }
  601. #endif // __RED_REDANIMATION_MANAGER_H__