2014-10-15 11:23:02 +08:00
|
|
|
/******************************************************************************
|
2019-12-12 23:26:12 +08:00
|
|
|
* Spine Runtimes License Agreement
|
2020-01-05 03:09:32 +08:00
|
|
|
* Last updated January 1, 2020. Replaces all prior versions.
|
2017-02-09 16:57:42 +08:00
|
|
|
*
|
2020-01-05 03:09:32 +08:00
|
|
|
* Copyright (c) 2013-2020, Esoteric Software LLC
|
2017-02-09 16:57:42 +08:00
|
|
|
*
|
2019-12-12 23:26:12 +08:00
|
|
|
* 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
|
2017-02-09 16:57:42 +08:00
|
|
|
*
|
2019-12-12 23:26:12 +08:00
|
|
|
* 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.
|
|
|
|
*
|
2020-01-05 03:09:32 +08:00
|
|
|
* 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.
|
2014-10-15 11:23:02 +08:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef SPINE_SKELETONANIMATION_H_
|
|
|
|
#define SPINE_SKELETONANIMATION_H_
|
2020-01-05 03:09:32 +08:00
|
|
|
|
2014-10-15 11:23:02 +08:00
|
|
|
#include <spine/spine.h>
|
2020-01-05 03:09:32 +08:00
|
|
|
#include <spine/spine-cocos2dx.h>
|
2014-10-15 11:23:02 +08:00
|
|
|
#include "cocos2d.h"
|
|
|
|
|
|
|
|
namespace spine {
|
|
|
|
|
2020-01-05 03:09:32 +08:00
|
|
|
class SkeletonAnimation;
|
|
|
|
|
2019-12-12 23:26:12 +08:00
|
|
|
typedef std::function<void(TrackEntry* entry)> StartListener;
|
|
|
|
typedef std::function<void(TrackEntry* entry)> InterruptListener;
|
|
|
|
typedef std::function<void(TrackEntry* entry)> EndListener;
|
|
|
|
typedef std::function<void(TrackEntry* entry)> DisposeListener;
|
|
|
|
typedef std::function<void(TrackEntry* entry)> CompleteListener;
|
|
|
|
typedef std::function<void(TrackEntry* entry, Event* event)> EventListener;
|
2020-01-05 03:09:32 +08:00
|
|
|
typedef std::function<void(SkeletonAnimation* node)> UpdateWorldTransformsListener;
|
2014-10-15 11:23:02 +08:00
|
|
|
|
|
|
|
/** 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:
|
2016-07-28 22:25:50 +08:00
|
|
|
CREATE_FUNC(SkeletonAnimation);
|
2019-12-12 23:26:12 +08:00
|
|
|
static SkeletonAnimation* createWithData (SkeletonData* skeletonData, bool ownsSkeletonData = false);
|
|
|
|
static SkeletonAnimation* createWithJsonFile (const std::string& skeletonJsonFile, Atlas* atlas, float scale = 1);
|
2016-10-12 01:56:14 +08:00
|
|
|
static SkeletonAnimation* createWithJsonFile (const std::string& skeletonJsonFile, const std::string& atlasFile, float scale = 1);
|
2019-12-12 23:26:12 +08:00
|
|
|
static SkeletonAnimation* createWithBinaryFile (const std::string& skeletonBinaryFile, Atlas* atlas, float scale = 1);
|
2016-10-12 01:56:14 +08:00
|
|
|
static SkeletonAnimation* createWithBinaryFile (const std::string& skeletonBinaryFile, const std::string& atlasFile, float scale = 1);
|
|
|
|
|
|
|
|
// Use createWithJsonFile instead
|
2019-12-12 23:26:12 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static SkeletonAnimation* createWithFile (const std::string& skeletonJsonFile, Atlas* atlas, float scale = 1)
|
2016-10-12 01:56:14 +08:00
|
|
|
{
|
|
|
|
return SkeletonAnimation::createWithJsonFile(skeletonJsonFile, atlas, scale);
|
|
|
|
}
|
|
|
|
// Use createWithJsonFile instead
|
2017-12-08 17:23:08 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static SkeletonAnimation* createWithFile (const std::string& skeletonJsonFile, const std::string& atlasFile, float scale = 1)
|
2016-10-12 01:56:14 +08:00
|
|
|
{
|
|
|
|
return SkeletonAnimation::createWithJsonFile(skeletonJsonFile, atlasFile, scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void update (float deltaTime) override;
|
2019-12-12 23:26:12 +08:00
|
|
|
virtual void draw (cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t transformFlags) override;
|
2014-10-15 11:23:02 +08:00
|
|
|
|
2019-12-12 23:26:12 +08:00
|
|
|
void setAnimationStateData (AnimationStateData* stateData);
|
2014-10-15 11:23:02 +08:00
|
|
|
void setMix (const std::string& fromAnimation, const std::string& toAnimation, float duration);
|
|
|
|
|
2019-12-12 23:26:12 +08:00
|
|
|
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);
|
2017-11-02 09:06:13 +08:00
|
|
|
void setEmptyAnimations (float mixDuration);
|
2019-12-12 23:26:12 +08:00
|
|
|
TrackEntry* addEmptyAnimation (int trackIndex, float mixDuration, float delay = 0);
|
|
|
|
Animation* findAnimation(const std::string& name) const;
|
|
|
|
TrackEntry* getCurrent (int trackIndex = 0);
|
2014-10-15 11:23:02 +08:00
|
|
|
void clearTracks ();
|
|
|
|
void clearTrack (int trackIndex = 0);
|
|
|
|
|
|
|
|
void setStartListener (const StartListener& listener);
|
2020-01-05 03:09:32 +08:00
|
|
|
void setInterruptListener (const InterruptListener& listener);
|
2014-10-15 11:23:02 +08:00
|
|
|
void setEndListener (const EndListener& listener);
|
2020-01-05 03:09:32 +08:00
|
|
|
void setDisposeListener (const DisposeListener& listener);
|
2014-10-15 11:23:02 +08:00
|
|
|
void setCompleteListener (const CompleteListener& listener);
|
|
|
|
void setEventListener (const EventListener& listener);
|
2020-01-05 03:09:32 +08:00
|
|
|
void setPreUpdateWorldTransformsListener(const UpdateWorldTransformsListener& listener);
|
|
|
|
void setPostUpdateWorldTransformsListener(const UpdateWorldTransformsListener& listener);
|
2014-10-15 11:23:02 +08:00
|
|
|
|
2019-12-12 23:26:12 +08:00
|
|
|
void setTrackStartListener (TrackEntry* entry, const StartListener& listener);
|
2020-01-05 03:09:32 +08:00
|
|
|
void setTrackInterruptListener (TrackEntry* entry, const InterruptListener& listener);
|
2019-12-12 23:26:12 +08:00
|
|
|
void setTrackEndListener (TrackEntry* entry, const EndListener& listener);
|
2020-01-05 03:09:32 +08:00
|
|
|
void setTrackDisposeListener (TrackEntry* entry, const DisposeListener& listener);
|
2019-12-12 23:26:12 +08:00
|
|
|
void setTrackCompleteListener (TrackEntry* entry, const CompleteListener& listener);
|
|
|
|
void setTrackEventListener (TrackEntry* entry, const EventListener& listener);
|
2014-10-15 11:23:02 +08:00
|
|
|
|
2019-12-12 23:26:12 +08:00
|
|
|
virtual void onAnimationStateEvent (TrackEntry* entry, EventType type, Event* event);
|
|
|
|
virtual void onTrackEntryEvent (TrackEntry* entry, EventType type, Event* event);
|
2014-10-15 11:23:02 +08:00
|
|
|
|
2019-12-12 23:26:12 +08:00
|
|
|
AnimationState* getState() const;
|
2020-01-05 03:09:32 +08:00
|
|
|
void setUpdateOnlyIfVisible(bool status);
|
2014-10-15 11:23:02 +08:00
|
|
|
|
2015-04-14 15:23:16 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2014-10-15 11:23:02 +08:00
|
|
|
SkeletonAnimation ();
|
|
|
|
virtual ~SkeletonAnimation ();
|
2016-10-12 01:56:14 +08:00
|
|
|
virtual void initialize () override;
|
2014-10-15 11:23:02 +08:00
|
|
|
|
2015-04-14 15:23:16 +08:00
|
|
|
protected:
|
2019-12-12 23:26:12 +08:00
|
|
|
AnimationState* _state;
|
2014-10-15 11:23:02 +08:00
|
|
|
|
|
|
|
bool _ownsAnimationStateData;
|
2020-01-05 03:09:32 +08:00
|
|
|
bool _updateOnlyIfVisible;
|
2019-12-12 23:26:12 +08:00
|
|
|
bool _firstDraw;
|
2014-10-15 11:23:02 +08:00
|
|
|
|
|
|
|
StartListener _startListener;
|
2020-01-05 03:09:32 +08:00
|
|
|
InterruptListener _interruptListener;
|
2014-10-15 11:23:02 +08:00
|
|
|
EndListener _endListener;
|
2020-01-05 03:09:32 +08:00
|
|
|
DisposeListener _disposeListener;
|
2014-10-15 11:23:02 +08:00
|
|
|
CompleteListener _completeListener;
|
|
|
|
EventListener _eventListener;
|
2020-01-05 03:09:32 +08:00
|
|
|
UpdateWorldTransformsListener _preUpdateListener;
|
|
|
|
UpdateWorldTransformsListener _postUpdateListener;
|
2014-10-15 11:23:02 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
typedef SkeletonRenderer super;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* SPINE_SKELETONANIMATION_H_ */
|