mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Adds Binary support to cocos2d-x (#716)
- it simplifies the constructors/initializors - the binary API is ::createWithBinaryFile() - the JSON API is :: createWithJsonFile() - the old API ::createWithDataFile() is deprecated and calls createWithJsonFile()
This commit is contained in:
parent
ea0c2ae704
commit
efe0b55dbb
@ -72,24 +72,46 @@ void disposeTrackEntry (spTrackEntry* entry) {
|
|||||||
//
|
//
|
||||||
|
|
||||||
SkeletonAnimation* SkeletonAnimation::createWithData (spSkeletonData* skeletonData, bool ownsSkeletonData) {
|
SkeletonAnimation* SkeletonAnimation::createWithData (spSkeletonData* skeletonData, bool ownsSkeletonData) {
|
||||||
SkeletonAnimation* node = new SkeletonAnimation(skeletonData, ownsSkeletonData);
|
SkeletonAnimation* node = new SkeletonAnimation();
|
||||||
|
node->initWithData(skeletonData, ownsSkeletonData);
|
||||||
node->autorelease();
|
node->autorelease();
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkeletonAnimation* SkeletonAnimation::createWithFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale) {
|
SkeletonAnimation* SkeletonAnimation::createWithJsonFile (const std::string& skeletonJsonFile, spAtlas* atlas, float scale) {
|
||||||
SkeletonAnimation* node = new SkeletonAnimation(skeletonDataFile, atlas, scale);
|
SkeletonAnimation* node = new SkeletonAnimation();
|
||||||
|
node->initWithJsonFile(skeletonJsonFile, atlas, scale);
|
||||||
node->autorelease();
|
node->autorelease();
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkeletonAnimation* SkeletonAnimation::createWithFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) {
|
SkeletonAnimation* SkeletonAnimation::createWithJsonFile (const std::string& skeletonJsonFile, const std::string& atlasFile, float scale) {
|
||||||
SkeletonAnimation* node = new SkeletonAnimation(skeletonDataFile, atlasFile, scale);
|
SkeletonAnimation* node = new SkeletonAnimation();
|
||||||
|
spAtlas* atlas = spAtlas_createFromFile(atlasFile.c_str(), 0);
|
||||||
|
node->initWithJsonFile(skeletonJsonFile, atlas, scale);
|
||||||
node->autorelease();
|
node->autorelease();
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SkeletonAnimation* SkeletonAnimation::createWithBinaryFile (const std::string& skeletonBinaryFile, spAtlas* atlas, float scale) {
|
||||||
|
SkeletonAnimation* node = new SkeletonAnimation();
|
||||||
|
node->initWithBinaryFile(skeletonBinaryFile, atlas, scale);
|
||||||
|
node->autorelease();
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
SkeletonAnimation* SkeletonAnimation::createWithBinaryFile (const std::string& skeletonBinaryFile, const std::string& atlasFile, float scale) {
|
||||||
|
SkeletonAnimation* node = new SkeletonAnimation();
|
||||||
|
spAtlas* atlas = spAtlas_createFromFile(atlasFile.c_str(), 0);
|
||||||
|
node->initWithBinaryFile(skeletonBinaryFile, atlas, scale);
|
||||||
|
node->autorelease();
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SkeletonAnimation::initialize () {
|
void SkeletonAnimation::initialize () {
|
||||||
|
super::initialize();
|
||||||
|
|
||||||
_ownsAnimationStateData = true;
|
_ownsAnimationStateData = true;
|
||||||
_state = spAnimationState_create(spAnimationStateData_create(_skeleton->data));
|
_state = spAnimationState_create(spAnimationStateData_create(_skeleton->data));
|
||||||
_state->rendererObject = this;
|
_state->rendererObject = this;
|
||||||
@ -103,21 +125,6 @@ SkeletonAnimation::SkeletonAnimation ()
|
|||||||
: SkeletonRenderer() {
|
: SkeletonRenderer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
SkeletonAnimation::SkeletonAnimation (spSkeletonData *skeletonData, bool ownsSkeletonData)
|
|
||||||
: SkeletonRenderer(skeletonData, ownsSkeletonData) {
|
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
SkeletonAnimation::SkeletonAnimation (const std::string& skeletonDataFile, spAtlas* atlas, float scale)
|
|
||||||
: SkeletonRenderer(skeletonDataFile, atlas, scale) {
|
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
SkeletonAnimation::SkeletonAnimation (const std::string& skeletonDataFile, const std::string& atlasFile, float scale)
|
|
||||||
: SkeletonRenderer(skeletonDataFile, atlasFile, scale) {
|
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
SkeletonAnimation::~SkeletonAnimation () {
|
SkeletonAnimation::~SkeletonAnimation () {
|
||||||
if (_ownsAnimationStateData) spAnimationStateData_dispose(_state->data);
|
if (_ownsAnimationStateData) spAnimationStateData_dispose(_state->data);
|
||||||
spAnimationState_dispose(_state);
|
spAnimationState_dispose(_state);
|
||||||
@ -165,9 +172,9 @@ spTrackEntry* SkeletonAnimation::addAnimation (int trackIndex, const std::string
|
|||||||
}
|
}
|
||||||
return spAnimationState_addAnimation(_state, trackIndex, animation, loop, delay);
|
return spAnimationState_addAnimation(_state, trackIndex, animation, loop, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
spAnimation* SkeletonAnimation::findAnimation(const std::string& name) const {
|
spAnimation* SkeletonAnimation::findAnimation(const std::string& name) const {
|
||||||
return spSkeletonData_findAnimation(_skeleton->data, name.c_str());
|
return spSkeletonData_findAnimation(_skeleton->data, name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
spTrackEntry* SkeletonAnimation::getCurrent (int trackIndex) {
|
spTrackEntry* SkeletonAnimation::getCurrent (int trackIndex) {
|
||||||
|
|||||||
@ -49,17 +49,30 @@ class SkeletonAnimation: public SkeletonRenderer {
|
|||||||
public:
|
public:
|
||||||
CREATE_FUNC(SkeletonAnimation);
|
CREATE_FUNC(SkeletonAnimation);
|
||||||
static SkeletonAnimation* createWithData (spSkeletonData* skeletonData, bool ownsSkeletonData = false);
|
static SkeletonAnimation* createWithData (spSkeletonData* skeletonData, bool ownsSkeletonData = false);
|
||||||
static SkeletonAnimation* createWithFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale = 1);
|
static SkeletonAnimation* createWithJsonFile (const std::string& skeletonJsonFile, spAtlas* atlas, float scale = 1);
|
||||||
static SkeletonAnimation* createWithFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1);
|
static SkeletonAnimation* createWithJsonFile (const std::string& skeletonJsonFile, const std::string& atlasFile, float scale = 1);
|
||||||
|
static SkeletonAnimation* createWithBinaryFile (const std::string& skeletonBinaryFile, spAtlas* atlas, float scale = 1);
|
||||||
|
static SkeletonAnimation* createWithBinaryFile (const std::string& skeletonBinaryFile, const std::string& atlasFile, float scale = 1);
|
||||||
|
|
||||||
virtual void update (float deltaTime);
|
// Use createWithJsonFile instead
|
||||||
|
CC_DEPRECATED_ATTRIBUTE static SkeletonAnimation* createWithFile (const std::string& skeletonJsonFile, spAtlas* atlas, float scale = 1)
|
||||||
|
{
|
||||||
|
return SkeletonAnimation::createWithJsonFile(skeletonJsonFile, atlas, scale);
|
||||||
|
}
|
||||||
|
// Use createWithJsonFile instead
|
||||||
|
CC_DEPRECATED_ATTRIBUTE static SkeletonAnimation* createWithile (const std::string& skeletonJsonFile, const std::string& atlasFile, float scale = 1)
|
||||||
|
{
|
||||||
|
return SkeletonAnimation::createWithJsonFile(skeletonJsonFile, atlasFile, scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void update (float deltaTime) override;
|
||||||
|
|
||||||
void setAnimationStateData (spAnimationStateData* stateData);
|
void setAnimationStateData (spAnimationStateData* stateData);
|
||||||
void setMix (const std::string& fromAnimation, const std::string& toAnimation, float duration);
|
void setMix (const std::string& fromAnimation, const std::string& toAnimation, float duration);
|
||||||
|
|
||||||
spTrackEntry* setAnimation (int trackIndex, const std::string& name, bool loop);
|
spTrackEntry* setAnimation (int trackIndex, const std::string& name, bool loop);
|
||||||
spTrackEntry* addAnimation (int trackIndex, const std::string& name, bool loop, float delay = 0);
|
spTrackEntry* addAnimation (int trackIndex, const std::string& name, bool loop, float delay = 0);
|
||||||
spAnimation* findAnimation(const std::string& name) const;
|
spAnimation* findAnimation(const std::string& name) const;
|
||||||
spTrackEntry* getCurrent (int trackIndex = 0);
|
spTrackEntry* getCurrent (int trackIndex = 0);
|
||||||
void clearTracks ();
|
void clearTracks ();
|
||||||
void clearTrack (int trackIndex = 0);
|
void clearTrack (int trackIndex = 0);
|
||||||
@ -81,11 +94,8 @@ public:
|
|||||||
|
|
||||||
CC_CONSTRUCTOR_ACCESS:
|
CC_CONSTRUCTOR_ACCESS:
|
||||||
SkeletonAnimation ();
|
SkeletonAnimation ();
|
||||||
SkeletonAnimation (spSkeletonData* skeletonData, bool ownsSkeletonData = false);
|
|
||||||
SkeletonAnimation (const std::string&skeletonDataFile, spAtlas* atlas, float scale = 1);
|
|
||||||
SkeletonAnimation (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1);
|
|
||||||
virtual ~SkeletonAnimation ();
|
virtual ~SkeletonAnimation ();
|
||||||
void initialize ();
|
virtual void initialize () override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
spAnimationState* _state;
|
spAnimationState* _state;
|
||||||
|
|||||||
@ -38,34 +38,34 @@ USING_NS_CC;
|
|||||||
using std::max;
|
using std::max;
|
||||||
|
|
||||||
namespace spine {
|
namespace spine {
|
||||||
|
|
||||||
static SkeletonBatch* instance = nullptr;
|
static SkeletonBatch* instance = nullptr;
|
||||||
|
|
||||||
SkeletonBatch* SkeletonBatch::getInstance () {
|
SkeletonBatch* SkeletonBatch::getInstance () {
|
||||||
if (!instance) instance = new SkeletonBatch();
|
if (!instance) instance = new SkeletonBatch();
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonBatch::destroyInstance () {
|
void SkeletonBatch::destroyInstance () {
|
||||||
if (instance) {
|
if (instance) {
|
||||||
delete instance;
|
delete instance;
|
||||||
instance = nullptr;
|
instance = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SkeletonBatch::SkeletonBatch ()
|
SkeletonBatch::SkeletonBatch ()
|
||||||
{
|
{
|
||||||
_firstCommand = new Command();
|
_firstCommand = new Command();
|
||||||
_command = _firstCommand;
|
_command = _firstCommand;
|
||||||
|
|
||||||
Director::getInstance()->getEventDispatcher()->addCustomEventListener(EVENT_AFTER_DRAW_RESET_POSITION, [this](EventCustom* eventCustom){
|
Director::getInstance()->getEventDispatcher()->addCustomEventListener(EVENT_AFTER_DRAW_RESET_POSITION, [this](EventCustom* eventCustom){
|
||||||
this->update(0);
|
this->update(0);
|
||||||
});;
|
});;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkeletonBatch::~SkeletonBatch () {
|
SkeletonBatch::~SkeletonBatch () {
|
||||||
Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(EVENT_AFTER_DRAW_RESET_POSITION);
|
Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(EVENT_AFTER_DRAW_RESET_POSITION);
|
||||||
|
|
||||||
Command* command = _firstCommand;
|
Command* command = _firstCommand;
|
||||||
while (command) {
|
while (command) {
|
||||||
Command* next = command->next;
|
Command* next = command->next;
|
||||||
@ -73,37 +73,37 @@ namespace spine {
|
|||||||
command = next;
|
command = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonBatch::update (float delta) {
|
void SkeletonBatch::update (float delta) {
|
||||||
_command = _firstCommand;
|
_command = _firstCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonBatch::addCommand (cocos2d::Renderer* renderer, float globalZOrder, GLuint textureID, GLProgramState* glProgramState,
|
void SkeletonBatch::addCommand (cocos2d::Renderer* renderer, float globalZOrder, GLuint textureID, GLProgramState* glProgramState,
|
||||||
BlendFunc blendFunc, const TrianglesCommand::Triangles& triangles, const Mat4& transform, uint32_t transformFlags
|
BlendFunc blendFunc, const TrianglesCommand::Triangles& triangles, const Mat4& transform, uint32_t transformFlags
|
||||||
) {
|
) {
|
||||||
_command->triangles->verts = triangles.verts;
|
_command->triangles->verts = triangles.verts;
|
||||||
|
|
||||||
_command->triangles->vertCount = triangles.vertCount;
|
_command->triangles->vertCount = triangles.vertCount;
|
||||||
_command->triangles->indexCount = triangles.indexCount;
|
_command->triangles->indexCount = triangles.indexCount;
|
||||||
_command->triangles->indices = triangles.indices;
|
_command->triangles->indices = triangles.indices;
|
||||||
|
|
||||||
_command->trianglesCommand->init(globalZOrder, textureID, glProgramState, blendFunc, *_command->triangles, transform);
|
_command->trianglesCommand->init(globalZOrder, textureID, glProgramState, blendFunc, *_command->triangles, transform);
|
||||||
renderer->addCommand(_command->trianglesCommand);
|
renderer->addCommand(_command->trianglesCommand);
|
||||||
|
|
||||||
if (!_command->next) _command->next = new Command();
|
if (!_command->next) _command->next = new Command();
|
||||||
_command = _command->next;
|
_command = _command->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkeletonBatch::Command::Command () :
|
SkeletonBatch::Command::Command () :
|
||||||
next(nullptr)
|
next(nullptr)
|
||||||
{
|
{
|
||||||
trianglesCommand = new TrianglesCommand();
|
trianglesCommand = new TrianglesCommand();
|
||||||
triangles = new TrianglesCommand::Triangles();
|
triangles = new TrianglesCommand::Triangles();
|
||||||
}
|
}
|
||||||
|
|
||||||
SkeletonBatch::Command::~Command () {
|
SkeletonBatch::Command::~Command () {
|
||||||
delete triangles;
|
delete triangles;
|
||||||
delete trianglesCommand;
|
delete trianglesCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user