SkeletonAnimation.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /******************************************************************************
  2. * Spine Runtimes Software License v2.5
  3. *
  4. * Copyright (c) 2013-2016, Esoteric Software
  5. * All rights reserved.
  6. *
  7. * You are granted a perpetual, non-exclusive, non-sublicensable, and
  8. * non-transferable license to use, install, execute, and perform the Spine
  9. * Runtimes software and derivative works solely for personal or internal
  10. * use. Without the written permission of Esoteric Software (see Section 2 of
  11. * the Spine Software License Agreement), you may not (a) modify, translate,
  12. * adapt, or develop new applications using the Spine Runtimes or otherwise
  13. * create derivative works or improvements of the Spine Runtimes or (b) remove,
  14. * delete, alter, or obscure any trademarks or any copyright, trademark, patent,
  15. * or other intellectual property or proprietary rights notices on or in the
  16. * Software, including any copy thereof. Redistributions in binary or source
  17. * form must include this license and terms.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
  20. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  22. * EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
  25. * USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  26. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. *****************************************************************************/
  30. #ifndef SPINE_SKELETONANIMATION_H_
  31. #define SPINE_SKELETONANIMATION_H_
  32. #include <spine/spine.h>
  33. #include <spine/SkeletonRenderer.h>
  34. #include "cocos2d.h"
  35. namespace spine {
  36. typedef std::function<void(spTrackEntry* entry)> StartListener;
  37. typedef std::function<void(spTrackEntry* entry)> InterruptListener;
  38. typedef std::function<void(spTrackEntry* entry)> EndListener;
  39. typedef std::function<void(spTrackEntry* entry)> DisposeListener;
  40. typedef std::function<void(spTrackEntry* entry)> CompleteListener;
  41. typedef std::function<void(spTrackEntry* entry, spEvent* event)> EventListener;
  42. /** Draws an animated skeleton, providing an AnimationState for applying one or more animations and queuing animations to be
  43. * played later. */
  44. class SkeletonAnimation: public SkeletonRenderer {
  45. public:
  46. CREATE_FUNC(SkeletonAnimation);
  47. static SkeletonAnimation* createWithData (spSkeletonData* skeletonData, bool ownsSkeletonData = false);
  48. static SkeletonAnimation* createWithJsonFile (const std::string& skeletonJsonFile, spAtlas* atlas, float scale = 1);
  49. static SkeletonAnimation* createWithJsonFile (const std::string& skeletonJsonFile, const std::string& atlasFile, float scale = 1);
  50. static SkeletonAnimation* createWithBinaryFile (const std::string& skeletonBinaryFile, spAtlas* atlas, float scale = 1);
  51. static SkeletonAnimation* createWithBinaryFile (const std::string& skeletonBinaryFile, const std::string& atlasFile, float scale = 1);
  52. // Use createWithJsonFile instead
  53. CC_DEPRECATED_ATTRIBUTE static SkeletonAnimation* createWithFile (const std::string& skeletonJsonFile, spAtlas* atlas, float scale = 1)
  54. {
  55. return SkeletonAnimation::createWithJsonFile(skeletonJsonFile, atlas, scale);
  56. }
  57. // Use createWithJsonFile instead
  58. CC_DEPRECATED_ATTRIBUTE static SkeletonAnimation* createWithile (const std::string& skeletonJsonFile, const std::string& atlasFile, float scale = 1)
  59. {
  60. return SkeletonAnimation::createWithJsonFile(skeletonJsonFile, atlasFile, scale);
  61. }
  62. virtual void update (float deltaTime) override;
  63. void setAnimationStateData (spAnimationStateData* stateData);
  64. void setMix (const std::string& fromAnimation, const std::string& toAnimation, float duration);
  65. spTrackEntry* setAnimation (int trackIndex, const std::string& name, bool loop);
  66. spTrackEntry* addAnimation (int trackIndex, const std::string& name, bool loop, float delay = 0);
  67. spAnimation* findAnimation(const std::string& name) const;
  68. spTrackEntry* getCurrent (int trackIndex = 0);
  69. void clearTracks ();
  70. void clearTrack (int trackIndex = 0);
  71. void setStartListener (const StartListener& listener);
  72. void setInterruptListener (const InterruptListener& listener);
  73. void setEndListener (const EndListener& listener);
  74. void setDisposeListener (const DisposeListener& listener);
  75. void setCompleteListener (const CompleteListener& listener);
  76. void setEventListener (const EventListener& listener);
  77. void setTrackStartListener (spTrackEntry* entry, const StartListener& listener);
  78. void setTrackInterruptListener (spTrackEntry* entry, const InterruptListener& listener);
  79. void setTrackEndListener (spTrackEntry* entry, const EndListener& listener);
  80. void setTrackDisposeListener (spTrackEntry* entry, const DisposeListener& listener);
  81. void setTrackCompleteListener (spTrackEntry* entry, const CompleteListener& listener);
  82. void setTrackEventListener (spTrackEntry* entry, const EventListener& listener);
  83. virtual void onAnimationStateEvent (spTrackEntry* entry, spEventType type, spEvent* event);
  84. virtual void onTrackEntryEvent (spTrackEntry* entry, spEventType type, spEvent* event);
  85. spAnimationState* getState() const;
  86. CC_CONSTRUCTOR_ACCESS:
  87. SkeletonAnimation ();
  88. virtual ~SkeletonAnimation ();
  89. virtual void initialize () override;
  90. protected:
  91. spAnimationState* _state;
  92. bool _ownsAnimationStateData;
  93. StartListener _startListener;
  94. InterruptListener _interruptListener;
  95. EndListener _endListener;
  96. DisposeListener _disposeListener;
  97. CompleteListener _completeListener;
  98. EventListener _eventListener;
  99. private:
  100. typedef SkeletonRenderer super;
  101. };
  102. }
  103. #endif /* SPINE_SKELETONANIMATION_H_ */