CCActionNode.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /****************************************************************************
  2. Copyright (c) 2013-2017 Chukong Technologies Inc.
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #ifndef __ActionNODE_H__
  21. #define __ActionNODE_H__
  22. #include "editor-support/cocostudio/CCActionFrame.h"
  23. #include "editor-support/cocostudio/DictionaryHelper.h"
  24. #include "editor-support/cocostudio/CocosStudioExport.h"
  25. namespace cocostudio {
  26. class CocoLoader;
  27. struct stExpCocoNode;
  28. /**
  29. * @js NA
  30. * @lua NA
  31. */
  32. class CC_STUDIO_DLL ActionNode : public cocos2d::Ref
  33. {
  34. public:
  35. /**
  36. * Default constructor
  37. */
  38. ActionNode();
  39. /**
  40. * Default destructor
  41. */
  42. virtual ~ActionNode();
  43. /**
  44. * Sets the time interval of frame.
  45. *
  46. * @param fTime the time interval of frame
  47. */
  48. void setUnitTime(float fTime);
  49. /**
  50. * Gets the time interval of frame.
  51. *
  52. * @return fTime the time interval of frame
  53. */
  54. float getUnitTime();
  55. /**
  56. * Sets tag for ActionNode
  57. *
  58. * @param tag tag of ActionNode
  59. */
  60. void setActionTag(int tag);
  61. /**
  62. * Gets tag for ActionNode
  63. *
  64. * @return tag tag of ActionNode
  65. */
  66. int getActionTag();
  67. /**
  68. * Sets node which will run a action.
  69. *
  70. * @param node which will run a action
  71. */
  72. void setObject(cocos2d::Ref* node);
  73. /**
  74. * Gets node which will run a action.
  75. *
  76. * @return node which will run a action
  77. */
  78. cocos2d::Ref* getObject();
  79. /**
  80. * Insets a ActionFrame to ActionNode.
  81. *
  82. * @param index the index of ActionFrame
  83. *
  84. * @param frame the ActionFrame which will be inserted
  85. */
  86. void insertFrame(int index, ActionFrame* frame);
  87. /**
  88. * Pushes back a ActionFrame to ActionNode.
  89. *
  90. * @param frame the ActionFrame which will be added
  91. */
  92. void addFrame(ActionFrame* frame);
  93. /**
  94. * Remove a ActionFrame from ActionNode.
  95. *
  96. * @param frame the ActionFrame which will be removed
  97. */
  98. void deleteFrame(ActionFrame* frame );
  99. /**
  100. * Remove all ActionFrames from ActionNode.
  101. */
  102. void clearAllFrame();
  103. /**
  104. * Gets index of first ActionFrame.
  105. *
  106. * @return index of first ActionFrame
  107. */
  108. int getFirstFrameIndex();
  109. /**
  110. * Gets index of last ActionFrame.
  111. *
  112. * @return index of last ActionFrame
  113. */
  114. int getLastFrameIndex();
  115. /**
  116. * Updates action states to some time.
  117. *
  118. * @param fTime the time when need to update
  119. */
  120. virtual bool updateActionToTimeLine(float fTime);
  121. /**
  122. * Play the action.
  123. */
  124. virtual void playAction();
  125. /**
  126. * Stop the action.
  127. */
  128. virtual void stopAction();
  129. /*init properties with a json dictionary*/
  130. virtual void initWithDictionary(const rapidjson::Value& dic, cocos2d::Ref* root);
  131. virtual void initWithBinary(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode, Ref* root);
  132. /**
  133. * Gets if the action is done once time.
  134. *
  135. * @return that if the action is done once time
  136. */
  137. virtual bool isActionDoneOnce();
  138. protected:
  139. int valueToInt(const std::string& value);
  140. bool valueToBool(const std::string& value);
  141. float valueToFloat(const std::string& value);
  142. int _currentFrameIndex;
  143. int _destFrameIndex;
  144. float _fUnitTime;
  145. int _actionTag;
  146. cocos2d::Spawn * _actionSpawn;
  147. cocos2d::Action* _action;
  148. cocos2d::Ref* _object;
  149. std::vector<cocos2d::Vector<ActionFrame*>*> _frameArray;
  150. int _frameArrayNum;
  151. protected:
  152. virtual cocos2d::Node* getActionNode();
  153. virtual cocos2d::Spawn * refreshActionProperty();
  154. virtual void runAction();
  155. virtual void initActionNodeFromRoot(cocos2d::Ref* root);
  156. virtual void easingToFrame(float duration,float delayTime,ActionFrame* srcFrame,ActionFrame* destFrame);
  157. };
  158. }
  159. #endif