1
0

CCTween.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 __CCTWEEN_H__
  21. #define __CCTWEEN_H__
  22. #include "editor-support/cocostudio/CCProcessBase.h"
  23. #include "2d/CCTweenFunction.h"
  24. #include "editor-support/cocostudio/CocosStudioExport.h"
  25. namespace cocostudio {
  26. class Bone;
  27. class ArmatureAnimation;
  28. using cocos2d::tweenfunc::TweenType;
  29. /**
  30. * @js NA
  31. * @lua NA
  32. */
  33. class CC_STUDIO_DLL Tween : public ProcessBase
  34. {
  35. public:
  36. /**
  37. * Create with a Bone
  38. * @param bone the Bone Tween will bind to
  39. */
  40. static Tween *create(Bone *bone);
  41. public:
  42. Tween(void);
  43. virtual ~Tween(void);
  44. /**
  45. * Init with a Bone
  46. * @param bone the Bone Tween will bind to
  47. */
  48. virtual bool init(Bone *bone);
  49. using ProcessBase::play;
  50. /**
  51. * Start the Process
  52. *
  53. * @param movementBoneData the MovementBoneData include all FrameData
  54. * @param durationTo the number of frames changing to this animation needs.
  55. * @param durationTween the number of frames this animation actual last.
  56. *
  57. * @param loop whether the animation is loop
  58. *
  59. * loop < 0 : use the value from MovementData get from Action Editor
  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 Action Editor
  66. * -1 : fade out
  67. * 0 : line
  68. * 1 : fade in
  69. * 2 : fade in and out
  70. *
  71. */
  72. virtual void play(MovementBoneData *movementBoneData, int durationTo, int durationTween, int loop, int tweenEasing);
  73. inline void setAnimation(ArmatureAnimation *animation) { _animation = animation; }
  74. inline ArmatureAnimation *getAnimation() const { return _animation; }
  75. virtual void gotoAndPlay(int frameIndex);
  76. virtual void gotoAndPause(int frameIndex);
  77. virtual void setMovementBoneData(MovementBoneData *data) { _movementBoneData = data; }
  78. virtual const MovementBoneData *getMovementBoneData() const { return _movementBoneData; }
  79. protected:
  80. /**
  81. * Update(float dt) will call this handler, you can handle your logic here
  82. */
  83. virtual void updateHandler();
  84. /**
  85. * Calculate which frame arrived, and if current frame have event, then call the event listener
  86. */
  87. virtual float updateFrameData(float currentPercent);
  88. /**
  89. * Calculate the between value of _from and _to, and give it to between frame data
  90. */
  91. virtual void setBetween(FrameData *from, FrameData *to, bool limit = true);
  92. /**
  93. * According to the percent to calculate current FrameData with tween effect
  94. */
  95. virtual FrameData *tweenNodeTo(float percent, FrameData *node = nullptr);
  96. /**
  97. * According to the percent to calculate current color with tween effect
  98. */
  99. virtual void tweenColorTo(float percent, FrameData *node);
  100. /**
  101. * Update display index and process the key frame event when arrived a key frame
  102. */
  103. virtual void arriveKeyFrame(FrameData *keyFrameData);
  104. protected:
  105. //! A weak reference to the current MovementBoneData. The data is in the data pool
  106. MovementBoneData *_movementBoneData;
  107. FrameData *_tweenData; //! The computational tween frame data, //! A weak reference to the Bone's tweenData
  108. FrameData *_from; //! From frame data, used for calculate between value
  109. FrameData *_to; //! To frame data, used for calculate between value
  110. FrameData *_between; //! Between frame data, used for calculate current FrameData(m_pNode) value
  111. Bone *_bone; //! A weak reference to the Bone
  112. TweenType _frameTweenEasing; //! Determine which tween effect current frame use
  113. int _betweenDuration; //! Current key frame will last _betweenDuration frames
  114. int _totalDuration;
  115. int _fromIndex; //! The current frame index in FrameList of MovementBoneData, it's different from m_iFrameIndex
  116. int _toIndex; //! The next frame index in FrameList of MovementBoneData, it's different from m_iFrameIndex
  117. ArmatureAnimation *_animation;
  118. bool _passLastFrame; //! If current frame index is more than the last frame's index
  119. };
  120. }
  121. #endif /*__CCTWEEN_H__*/