CCProcessBase.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 __CCPROCESSBASE_H__
  21. #define __CCPROCESSBASE_H__
  22. #include "editor-support/cocostudio/CCArmatureDefine.h"
  23. #include "editor-support/cocostudio/CCDatas.h"
  24. #include "editor-support/cocostudio/CocosStudioExport.h"
  25. namespace cocostudio {
  26. enum AnimationType
  27. {
  28. SINGLE_FRAME = -4, //! the animation just have one frame
  29. ANIMATION_NO_LOOP, //! the animation isn't loop
  30. ANIMATION_TO_LOOP_FRONT, //! the animation loop from front
  31. ANIMATION_TO_LOOP_BACK, //! the animation loop from back
  32. ANIMATION_LOOP_FRONT, //! the animation loop from front
  33. ANIMATION_LOOP_BACK, //! the animation loop from back
  34. ANIMATION_MAX,
  35. };
  36. /**
  37. * @js NA
  38. * @lua NA
  39. */
  40. class CC_STUDIO_DLL ProcessBase : public cocos2d::Ref
  41. {
  42. public:
  43. ProcessBase(void);
  44. virtual ~ProcessBase(void);
  45. /**
  46. * Play animation by animation name.
  47. *
  48. * @param durationTo The frames between two animation changing-over.
  49. * It's meaning is changing to this animation need how many frames
  50. *
  51. * -1 : use the value from MovementData get from flash design panel
  52. * @param durationTween The frame count you want to play in the game.
  53. * if _durationTween is 80, then the animation will played 80 frames in a loop
  54. *
  55. * -1 : use the value from MovementData get from flash design panel
  56. *
  57. * @param loop Whether the animation is loop
  58. *
  59. * loop < 0 : use the value from MovementData get from flash design panel
  60. * loop = 0 : this animation is not loop
  61. * loop > 0 : this animation is loop
  62. *
  63. * @param tweenEasing Tween easing is used for calculate easing effect
  64. *
  65. * TWEEN_EASING_MAX : use the value from MovementData get from flash design panel
  66. * -1 : fade out
  67. * 0 : line
  68. * 1 : fade in
  69. * 2 : fade in and out
  70. *
  71. */
  72. virtual void play(int durationTo, int durationTween, int loop, int tweenEasing);
  73. /**
  74. * Pause the Process
  75. */
  76. virtual void pause();
  77. /**
  78. * Resume the Process
  79. */
  80. virtual void resume();
  81. /**
  82. * Stop the Process
  83. */
  84. virtual void stop();
  85. /**
  86. * You should never call this function, unless you know what you do
  87. * Update the Process, include current process, current frame and son on
  88. *
  89. * @param The duration since last update
  90. */
  91. virtual void update(float dt);
  92. virtual int getCurrentFrameIndex();
  93. virtual void setProcessScale(float processScale) { _processScale = processScale; }
  94. virtual float getProcessScale() const { return _processScale; }
  95. virtual void setIsPause(bool pause) { _isPause = pause; }
  96. virtual bool isPause() const { return _isPause; }
  97. virtual void setIsComplete(bool complete) { _isComplete = complete; }
  98. virtual bool isComplete() const { return _isComplete; }
  99. virtual void setIsPlaying(bool playing) { _isPlaying = playing; }
  100. virtual bool isPlaying() const { return _isPlaying; }
  101. virtual float getCurrentPercent() const { return _currentPercent; }
  102. virtual int getRawDuration() const { return _rawDuration; }
  103. protected:
  104. virtual void gotoFrame(int frameIndex);
  105. /**
  106. * Update(float dt) will call this handler, you can handle your logic here
  107. */
  108. virtual void updateHandler() {};
  109. protected:
  110. //! Scale the process speed
  111. float _processScale;
  112. //! Set and get whether the animation is pause
  113. bool _isPause;
  114. //! Set and get whether the animation is complete
  115. bool _isComplete;
  116. //! Set and get whether the animation is playing
  117. bool _isPlaying;
  118. //! Current percent this process arrived
  119. float _currentPercent;
  120. //! The raw duration
  121. int _rawDuration;
  122. //! The animation whether or not loop
  123. AnimationType _loopType;
  124. //! The tween easing effect
  125. cocos2d::tweenfunc::TweenType _tweenEasing;
  126. //! The animation update speed
  127. float _animationInternal;
  128. protected:
  129. //! The duration frame count will run
  130. int _durationTween;
  131. //! Current frame this process arrived, this frame is tween frame
  132. float _currentFrame;
  133. //! Frame index it the time line
  134. int _curFrameIndex;
  135. //! Next frame this process need run to
  136. int _nextFrameIndex;
  137. bool _isLoopBack;
  138. };
  139. }
  140. #endif /*__CCPROCESSBASE_H__*/