CCActionObject.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 __ActionObject_H__
  21. #define __ActionObject_H__
  22. #include "editor-support/cocostudio/CCActionNode.h"
  23. #include "2d/CCActionInstant.h"
  24. #include "editor-support/cocostudio/DictionaryHelper.h"
  25. #include "editor-support/cocostudio/CocosStudioExport.h"
  26. namespace cocostudio {
  27. class CocoLoader;
  28. struct stExpCocoNode;
  29. /**
  30. * @js NA
  31. * @lua NA
  32. */
  33. class CC_STUDIO_DLL ActionObject : public cocos2d::Ref
  34. {
  35. public:
  36. /**
  37. * Default constructor
  38. */
  39. ActionObject();
  40. /**
  41. * Default destructor
  42. */
  43. virtual ~ActionObject();
  44. /**
  45. * Sets name for object
  46. *
  47. * @param name name of object
  48. */
  49. void setName(const char* name);
  50. /**
  51. * Gets name of object
  52. *
  53. * @return name of object
  54. */
  55. const char* getName();
  56. /**
  57. * Sets if the action will loop play.
  58. *
  59. * @param bLoop that if the action will loop play
  60. */
  61. void setLoop(bool bLoop);
  62. /**
  63. * Gets if the action will loop play.
  64. *
  65. * @return that if the action will loop play
  66. */
  67. bool getLoop();
  68. /**
  69. * Sets the time interval of frame.
  70. *
  71. * @param fTime the time interval of frame
  72. */
  73. void setUnitTime(float fTime);
  74. /**
  75. * Gets the time interval of frame.
  76. *
  77. * @return the time interval of frame
  78. */
  79. float getUnitTime();
  80. /**
  81. * Sets the current time of frame.
  82. *
  83. * @param fTime the current time of frame
  84. */
  85. void setCurrentTime(float fTime);
  86. /**
  87. * Gets the current time of frame.
  88. *
  89. * @return the current time of frame
  90. */
  91. float getCurrentTime();
  92. /**
  93. * Gets the total time of frame.
  94. *
  95. * @return the total time of frame
  96. */
  97. float getTotalTime();
  98. /**
  99. * Return if the action is playing.
  100. *
  101. * @return true if the action is playing, false the otherwise
  102. */
  103. bool isPlaying();
  104. /**
  105. * Play the action.
  106. */
  107. void play();
  108. /**
  109. * Play the action.
  110. *
  111. * @param func Action Call Back
  112. */
  113. void play(cocos2d::CallFunc* func);
  114. /**
  115. * Pause the action.
  116. */
  117. void pause();
  118. /**
  119. * Stop the action.
  120. */
  121. void stop();
  122. /**
  123. * Adds a ActionNode to play the action.
  124. *
  125. * @param node the ActionNode which will play the action
  126. */
  127. void addActionNode(ActionNode* node);
  128. /**
  129. * Removes a ActionNode which play the action.
  130. *
  131. * @param node the ActionNode which play the action
  132. */
  133. void removeActionNode(ActionNode* node);
  134. /*update frame method*/
  135. void updateToFrameByTime(float fTime);
  136. /*init properties with a json dictionary*/
  137. void initWithDictionary(const rapidjson::Value& dic, cocos2d::Ref* root);
  138. void initWithBinary(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode, cocos2d::Ref* root);
  139. /*scheduler update function*/
  140. void simulationActionUpdate(float dt);
  141. protected:
  142. int valueToInt(const std::string& value);
  143. bool valueToBool(const std::string& value);
  144. float valueToFloat(const std::string& value);
  145. cocos2d::Vector<ActionNode*> _actionNodeList;
  146. std::string _name;
  147. bool _loop;
  148. bool _bPause;
  149. bool _bPlaying;
  150. float _fUnitTime;
  151. float _currentTime;
  152. cocos2d::Scheduler *_pScheduler;
  153. cocos2d::CallFunc *_CallBack;
  154. float _fTotalTime;
  155. };
  156. }
  157. #endif