/****************************************************************************** * Spine Runtimes License Agreement * Last updated January 1, 2020. Replaces all prior versions. * * Copyright (c) 2013-2020, Esoteric Software LLC * * Integration of the Spine Runtimes into software or otherwise creating * derivative works of the Spine Runtimes is permitted under the terms and * conditions of Section 2 of the Spine Editor License Agreement: * http://esotericsoftware.com/spine-editor-license * * Otherwise, it is permitted to integrate the Spine Runtimes into software * or otherwise create derivative works of the Spine Runtimes (collectively, * "Products"), provided that each user of the Products must obtain their own * Spine Editor license and redistribution of the Products in any form must * include this license and copyright notice. * * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ #ifndef SPINE_SKELETONANIMATION_H_ #define SPINE_SKELETONANIMATION_H_ #include #include #include "cocos2d.h" namespace spine { struct SkeletonFrame { SkeletonFrame() { this->animation = ""; this->progress = 0; this->loop = true; } SkeletonFrame(std::string animation,float progress, bool loop) { this->animation = animation; this->progress = progress; this->loop = loop; }; std::string animation; float progress; bool loop; }; class SkeletonAnimation; typedef std::function StartListener; typedef std::function InterruptListener; typedef std::function EndListener; typedef std::function DisposeListener; typedef std::function CompleteListener; typedef std::function EventListener; typedef std::function UpdateWorldTransformsListener; /** Draws an animated skeleton, providing an AnimationState for applying one or more animations and queuing animations to be * played later. */ class SkeletonAnimation: public SkeletonRenderer { public: CREATE_FUNC(SkeletonAnimation); static SkeletonAnimation* createWithData (SkeletonData* skeletonData, bool ownsSkeletonData = false); static SkeletonAnimation* createWithJsonFile (const std::string& skeletonJsonFile, Atlas* atlas, float scale = 1); static SkeletonAnimation* createWithJsonFile (const std::string& skeletonJsonFile, const std::string& atlasFile, float scale = 1); static SkeletonAnimation* createWithBinaryFile (const std::string& skeletonBinaryFile, Atlas* atlas, float scale = 1); static SkeletonAnimation* createWithBinaryFile (const std::string& skeletonBinaryFile, const std::string& atlasFile, float scale = 1); // Use createWithJsonFile instead CC_DEPRECATED_ATTRIBUTE static SkeletonAnimation* createWithFile (const std::string& skeletonJsonFile, Atlas* atlas, float scale = 1) { return SkeletonAnimation::createWithJsonFile(skeletonJsonFile, atlas, scale); } // Use createWithJsonFile instead CC_DEPRECATED_ATTRIBUTE static SkeletonAnimation* createWithFile (const std::string& skeletonJsonFile, const std::string& atlasFile, float scale = 1) { return SkeletonAnimation::createWithJsonFile(skeletonJsonFile, atlasFile, scale); } virtual void update (float deltaTime) override; virtual void draw (cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t transformFlags) override; void setAnimationStateData (AnimationStateData* stateData); void setMix (const std::string& fromAnimation, const std::string& toAnimation, float duration); TrackEntry* setAnimation (int trackIndex, const std::string& name, bool loop); TrackEntry* addAnimation (int trackIndex, const std::string& name, bool loop, float delay = 0); TrackEntry* setEmptyAnimation (int trackIndex, float mixDuration); void setEmptyAnimations (float mixDuration); TrackEntry* addEmptyAnimation (int trackIndex, float mixDuration, float delay = 0); Animation* findAnimation(const std::string& name) const; TrackEntry* getCurrent (int trackIndex = 0); void clearTracks (); void clearTrack (int trackIndex = 0); void setStartListener (const StartListener& listener); void setInterruptListener (const InterruptListener& listener); void setEndListener (const EndListener& listener); void setDisposeListener (const DisposeListener& listener); void setCompleteListener (const CompleteListener& listener); void setEventListener (const EventListener& listener); void setPreUpdateWorldTransformsListener(const UpdateWorldTransformsListener& listener); void setPostUpdateWorldTransformsListener(const UpdateWorldTransformsListener& listener); void setTrackStartListener (TrackEntry* entry, const StartListener& listener); void setTrackInterruptListener (TrackEntry* entry, const InterruptListener& listener); void setTrackEndListener (TrackEntry* entry, const EndListener& listener); void setTrackDisposeListener (TrackEntry* entry, const DisposeListener& listener); void setTrackCompleteListener (TrackEntry* entry, const CompleteListener& listener); void setTrackEventListener (TrackEntry* entry, const EventListener& listener); virtual void onAnimationStateEvent (TrackEntry* entry, EventType type, Event* event); virtual void onTrackEntryEvent (TrackEntry* entry, EventType type, Event* event); AnimationState* getState() const; void setUpdateOnlyIfVisible(bool status); //add by yuntao. bool _checkOutScreen = false; cocos2d::Size _checkContentSz; void setNotCheckDrawAndUpdateIfOutScreen(const cocos2d::Size& contentSz, const cocos2d::Vec2& anchorPoint); bool beOutScreen(); void changeSkeleton(const std::string& skeletonJsonFile, const std::string& atlasFile, float scale = 1.0f); void setDataFile(const std::string& dataFile) ; void setAtlasFile(const std::string& atlasFile) ; const std::string getDataFile() const{ return _dataFile;} const std::string getAtlasFile() const{ return _atlasFile;} CC_CONSTRUCTOR_ACCESS: SkeletonAnimation (); virtual ~SkeletonAnimation (); virtual void initialize () override; protected: AnimationState* _state = nullptr; bool _ownsAnimationStateData; bool _updateOnlyIfVisible; bool _firstDraw; std::string _dataFile; std::string _atlasFile; StartListener _startListener; InterruptListener _interruptListener; EndListener _endListener; DisposeListener _disposeListener; CompleteListener _completeListener; EventListener _eventListener; UpdateWorldTransformsListener _preUpdateListener; UpdateWorldTransformsListener _postUpdateListener; private: typedef SkeletonRenderer super; }; class SpineActionInstant : public cocos2d::ActionInstant { public: /** creates a Place action with a position */ static SpineActionInstant* create(SkeletonFrame startFrame); /** * @js NA * @lua NA */ ~SpineActionInstant(); bool initWithSkeletonFrame(SkeletonFrame startFrame); // Overrides virtual void update(float time) override; virtual SpineActionInstant* clone() const override; virtual SpineActionInstant* reverse() const override; private: SkeletonFrame _startFrame; }; } #endif /* SPINE_SKELETONANIMATION_H_ */