mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
spine-cocos2dx updated to latest spine-c API.
This has some API breakage, sorry. The new AnimationState now handles multiple "tracks", which makes it easier to apply and queue multiple animations at the same time, no longer do we need multiple AnimationStates.
This commit is contained in:
parent
5b2dfe3311
commit
067a84339b
@ -22,11 +22,11 @@ bool ExampleLayer::init () {
|
|||||||
skeletonNode->setMix("walk", "jump", 0.2f);
|
skeletonNode->setMix("walk", "jump", 0.2f);
|
||||||
skeletonNode->setMix("jump", "walk", 0.4f);
|
skeletonNode->setMix("jump", "walk", 0.4f);
|
||||||
|
|
||||||
skeletonNode->setAnimation("walk", true);
|
skeletonNode->setAnimation(0, "walk", true);
|
||||||
// This shows how to setup animations to play back to back.
|
// This shows how to setup animations to play back to back.
|
||||||
//skeletonNode->addAnimation("jump", true);
|
//skeletonNode->addAnimation(0, "jump", false);
|
||||||
//skeletonNode->addAnimation("walk", true);
|
//skeletonNode->addAnimation(0, "walk", false);
|
||||||
//skeletonNode->addAnimation("jump", true);
|
//skeletonNode->addAnimation(0, "jump", true);
|
||||||
|
|
||||||
skeletonNode->timeScale = 0.3f;
|
skeletonNode->timeScale = 0.3f;
|
||||||
skeletonNode->debugBones = true;
|
skeletonNode->debugBones = true;
|
||||||
@ -46,10 +46,11 @@ bool ExampleLayer::init () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ExampleLayer::update (float deltaTime) {
|
void ExampleLayer::update (float deltaTime) {
|
||||||
if (skeletonNode->states[0]->loop) {
|
TrackEntry* entry = skeletonNode->getCurrent(0);
|
||||||
if (skeletonNode->states[0]->time > 2) skeletonNode->setAnimation("jump", false);
|
if (entry->loop) {
|
||||||
|
if (entry->time > 2) skeletonNode->setAnimation(0, "jump", false);
|
||||||
} else {
|
} else {
|
||||||
if (skeletonNode->states[0]->time > 1) skeletonNode->setAnimation("walk", true);
|
if (entry->time > 1) skeletonNode->setAnimation(0, "walk", true);
|
||||||
}
|
}
|
||||||
// if (skeletonNode->states[0]->time > 0.1) CCDirector::sharedDirector()->replaceScene(ExampleLayer::scene());
|
// if (entry->time > 0.1) CCDirector::sharedDirector()->replaceScene(ExampleLayer::scene());
|
||||||
}
|
}
|
||||||
@ -134,6 +134,8 @@
|
|||||||
<ClInclude Include="..\..\..\spine-c\include\spine\Bone.h" />
|
<ClInclude Include="..\..\..\spine-c\include\spine\Bone.h" />
|
||||||
<ClInclude Include="..\..\..\spine-c\include\spine\BoneData.h" />
|
<ClInclude Include="..\..\..\spine-c\include\spine\BoneData.h" />
|
||||||
<ClInclude Include="..\..\..\spine-c\include\spine\BoundingBoxAttachment.h" />
|
<ClInclude Include="..\..\..\spine-c\include\spine\BoundingBoxAttachment.h" />
|
||||||
|
<ClInclude Include="..\..\..\spine-c\include\spine\Event.h" />
|
||||||
|
<ClInclude Include="..\..\..\spine-c\include\spine\EventData.h" />
|
||||||
<ClInclude Include="..\..\..\spine-c\include\spine\extension.h" />
|
<ClInclude Include="..\..\..\spine-c\include\spine\extension.h" />
|
||||||
<ClInclude Include="..\..\..\spine-c\include\spine\RegionAttachment.h" />
|
<ClInclude Include="..\..\..\spine-c\include\spine\RegionAttachment.h" />
|
||||||
<ClInclude Include="..\..\..\spine-c\include\spine\Skeleton.h" />
|
<ClInclude Include="..\..\..\spine-c\include\spine\Skeleton.h" />
|
||||||
@ -164,6 +166,8 @@
|
|||||||
<ClCompile Include="..\..\..\spine-c\src\spine\Bone.c" />
|
<ClCompile Include="..\..\..\spine-c\src\spine\Bone.c" />
|
||||||
<ClCompile Include="..\..\..\spine-c\src\spine\BoneData.c" />
|
<ClCompile Include="..\..\..\spine-c\src\spine\BoneData.c" />
|
||||||
<ClCompile Include="..\..\..\spine-c\src\spine\BoundingBoxAttachment.c" />
|
<ClCompile Include="..\..\..\spine-c\src\spine\BoundingBoxAttachment.c" />
|
||||||
|
<ClCompile Include="..\..\..\spine-c\src\spine\Event.c" />
|
||||||
|
<ClCompile Include="..\..\..\spine-c\src\spine\EventData.c" />
|
||||||
<ClCompile Include="..\..\..\spine-c\src\spine\extension.c" />
|
<ClCompile Include="..\..\..\spine-c\src\spine\extension.c" />
|
||||||
<ClCompile Include="..\..\..\spine-c\src\spine\Json.c" />
|
<ClCompile Include="..\..\..\spine-c\src\spine\Json.c" />
|
||||||
<ClCompile Include="..\..\..\spine-c\src\spine\RegionAttachment.c" />
|
<ClCompile Include="..\..\..\spine-c\src\spine\RegionAttachment.c" />
|
||||||
|
|||||||
@ -99,6 +99,12 @@
|
|||||||
<ClInclude Include="..\..\..\spine-c\include\spine\SkeletonBounds.h">
|
<ClInclude Include="..\..\..\spine-c\include\spine\SkeletonBounds.h">
|
||||||
<Filter>Classes\spine-c</Filter>
|
<Filter>Classes\spine-c</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\..\spine-c\include\spine\Event.h">
|
||||||
|
<Filter>Classes\spine-c</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\..\spine-c\include\spine\EventData.h">
|
||||||
|
<Filter>Classes\spine-c</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="main.cpp">
|
<ClCompile Include="main.cpp">
|
||||||
@ -179,5 +185,11 @@
|
|||||||
<ClCompile Include="..\..\..\spine-c\src\spine\SkeletonBounds.c">
|
<ClCompile Include="..\..\..\spine-c\src\spine\SkeletonBounds.c">
|
||||||
<Filter>Classes\spine-c</Filter>
|
<Filter>Classes\spine-c</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\..\spine-c\src\spine\Event.c">
|
||||||
|
<Filter>Classes\spine-c</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\..\spine-c\src\spine\EventData.c">
|
||||||
|
<Filter>Classes\spine-c</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@ -39,9 +39,7 @@
|
|||||||
|
|
||||||
namespace spine {
|
namespace spine {
|
||||||
|
|
||||||
/**
|
/** Draws a skeleton. */
|
||||||
Draws a skeleton.
|
|
||||||
*/
|
|
||||||
class CCSkeleton: public cocos2d::CCNodeRGBA, public cocos2d::CCBlendProtocol {
|
class CCSkeleton: public cocos2d::CCNodeRGBA, public cocos2d::CCBlendProtocol {
|
||||||
public:
|
public:
|
||||||
Skeleton* skeleton;
|
Skeleton* skeleton;
|
||||||
|
|||||||
@ -60,96 +60,71 @@ CCSkeletonAnimation* CCSkeletonAnimation::createWithFile (const char* skeletonDa
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCSkeletonAnimation::initialize () {
|
||||||
|
state = AnimationState_create(AnimationStateData_create(skeleton->data));
|
||||||
|
}
|
||||||
|
|
||||||
CCSkeletonAnimation::CCSkeletonAnimation (SkeletonData *skeletonData)
|
CCSkeletonAnimation::CCSkeletonAnimation (SkeletonData *skeletonData)
|
||||||
: CCSkeleton(skeletonData) {
|
: CCSkeleton(skeletonData) {
|
||||||
addAnimationState();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
CCSkeletonAnimation::CCSkeletonAnimation (const char* skeletonDataFile, Atlas* atlas, float scale)
|
CCSkeletonAnimation::CCSkeletonAnimation (const char* skeletonDataFile, Atlas* atlas, float scale)
|
||||||
: CCSkeleton(skeletonDataFile, atlas, scale) {
|
: CCSkeleton(skeletonDataFile, atlas, scale) {
|
||||||
addAnimationState();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
CCSkeletonAnimation::CCSkeletonAnimation (const char* skeletonDataFile, const char* atlasFile, float scale)
|
CCSkeletonAnimation::CCSkeletonAnimation (const char* skeletonDataFile, const char* atlasFile, float scale)
|
||||||
: CCSkeleton(skeletonDataFile, atlasFile, scale) {
|
: CCSkeleton(skeletonDataFile, atlasFile, scale) {
|
||||||
addAnimationState();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
CCSkeletonAnimation::~CCSkeletonAnimation () {
|
CCSkeletonAnimation::~CCSkeletonAnimation () {
|
||||||
for (std::vector<AnimationStateData*>::iterator iter = stateDatas.begin(); iter != stateDatas.end(); ++iter)
|
if (ownsAnimationStateData) AnimationStateData_dispose(state->data);
|
||||||
AnimationStateData_dispose(*iter);
|
AnimationState_dispose(state);
|
||||||
|
|
||||||
for (std::vector<AnimationState*>::iterator iter = states.begin(); iter != states.end(); ++iter)
|
|
||||||
AnimationState_dispose(*iter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCSkeletonAnimation::update (float deltaTime) {
|
void CCSkeletonAnimation::update (float deltaTime) {
|
||||||
super::update(deltaTime);
|
super::update(deltaTime);
|
||||||
|
|
||||||
deltaTime *= timeScale;
|
deltaTime *= timeScale;
|
||||||
for (std::vector<AnimationState*>::iterator iter = states.begin(); iter != states.end(); ++iter) {
|
AnimationState_update(state, deltaTime);
|
||||||
AnimationState_update(*iter, deltaTime);
|
AnimationState_apply(state, skeleton);
|
||||||
AnimationState_apply(*iter, skeleton);
|
|
||||||
}
|
|
||||||
Skeleton_updateWorldTransform(skeleton);
|
Skeleton_updateWorldTransform(skeleton);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCSkeletonAnimation::addAnimationState (AnimationStateData* stateData) {
|
void CCSkeletonAnimation::setAnimationStateData (AnimationStateData* stateData) {
|
||||||
if (!stateData) {
|
|
||||||
stateData = AnimationStateData_create(skeleton->data);
|
|
||||||
stateDatas.push_back(stateData);
|
|
||||||
}
|
|
||||||
AnimationState* state = AnimationState_create(stateData);
|
|
||||||
states.push_back(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
AnimationState* CCSkeletonAnimation::getAnimationState (int stateIndex) {
|
|
||||||
CCAssert(stateIndex >= 0 && stateIndex < (int)states.size(), "stateIndex out of range.");
|
|
||||||
return states[stateIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCSkeletonAnimation::setAnimationStateData (AnimationStateData* stateData, int stateIndex) {
|
|
||||||
CCAssert(stateIndex >= 0 && stateIndex < (int)states.size(), "stateIndex out of range.");
|
|
||||||
CCAssert(stateData, "stateData cannot be null.");
|
CCAssert(stateData, "stateData cannot be null.");
|
||||||
|
|
||||||
AnimationState* state = states[stateIndex];
|
if (ownsAnimationStateData) AnimationStateData_dispose(state->data);
|
||||||
for (std::vector<AnimationStateData*>::iterator iter = stateDatas.begin(); iter != stateDatas.end(); ++iter) {
|
|
||||||
if (state->data == *iter) {
|
|
||||||
AnimationStateData_dispose(state->data);
|
|
||||||
stateDatas.erase(iter);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (std::vector<AnimationState*>::iterator iter = states.begin(); iter != states.end(); ++iter) {
|
|
||||||
if (state == *iter) {
|
|
||||||
states.erase(iter);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AnimationState_dispose(state);
|
AnimationState_dispose(state);
|
||||||
|
|
||||||
|
ownsAnimationStateData = true;
|
||||||
state = AnimationState_create(stateData);
|
state = AnimationState_create(stateData);
|
||||||
states[stateIndex] = state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCSkeletonAnimation::setMix (const char* fromAnimation, const char* toAnimation, float duration, int stateIndex) {
|
void CCSkeletonAnimation::setMix (const char* fromAnimation, const char* toAnimation, float duration) {
|
||||||
CCAssert(stateIndex >= 0 && stateIndex < (int)states.size(), "stateIndex out of range.");
|
AnimationStateData_setMixByName(state->data, fromAnimation, toAnimation, duration);
|
||||||
AnimationStateData_setMixByName(states[stateIndex]->data, fromAnimation, toAnimation, duration);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCSkeletonAnimation::setAnimation (const char* name, bool loop, int stateIndex) {
|
TrackEntry* CCSkeletonAnimation::setAnimation (int trackIndex, const char* name, bool loop) {
|
||||||
CCAssert(stateIndex >= 0 && stateIndex < (int)states.size(), "stateIndex out of range.");
|
return AnimationState_setAnimationByName(state, trackIndex, name, loop);
|
||||||
AnimationState_setAnimationByName(states[stateIndex], name, loop);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCSkeletonAnimation::addAnimation (const char* name, bool loop, float delay, int stateIndex) {
|
TrackEntry* CCSkeletonAnimation::addAnimation (int trackIndex, const char* name, bool loop, float delay) {
|
||||||
CCAssert(stateIndex >= 0 && stateIndex < (int)states.size(), "stateIndex out of range.");
|
return AnimationState_addAnimationByName(state, trackIndex, name, loop, delay);
|
||||||
AnimationState_addAnimationByName(states[stateIndex], name, loop, delay);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCSkeletonAnimation::clearAnimation (int stateIndex) {
|
TrackEntry* CCSkeletonAnimation::getCurrent (int trackIndex) {
|
||||||
CCAssert(stateIndex >= 0 && stateIndex < (int)states.size(), "stateIndex out of range.");
|
return AnimationState_getCurrent(state, trackIndex);
|
||||||
AnimationState_clearAnimation(states[stateIndex]);
|
}
|
||||||
|
|
||||||
|
void CCSkeletonAnimation::clearAnimation () {
|
||||||
|
AnimationState_clear(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCSkeletonAnimation::clearAnimation (int trackIndex) {
|
||||||
|
AnimationState_clearTrack(state, trackIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,12 +40,11 @@
|
|||||||
|
|
||||||
namespace spine {
|
namespace spine {
|
||||||
|
|
||||||
/**
|
/** Draws an animated skeleton, providing an AnimationState for applying one or more animations and queuing animations to be
|
||||||
Draws an animated skeleton, providing a simple API for applying one or more animations and queuing animations to be played later.
|
* played later. */
|
||||||
*/
|
|
||||||
class CCSkeletonAnimation: public CCSkeleton {
|
class CCSkeletonAnimation: public CCSkeleton {
|
||||||
public:
|
public:
|
||||||
std::vector<AnimationState*> states;
|
AnimationState* state;
|
||||||
|
|
||||||
static CCSkeletonAnimation* createWithData (SkeletonData* skeletonData);
|
static CCSkeletonAnimation* createWithData (SkeletonData* skeletonData);
|
||||||
static CCSkeletonAnimation* createWithFile (const char* skeletonDataFile, Atlas* atlas, float scale = 1);
|
static CCSkeletonAnimation* createWithFile (const char* skeletonDataFile, Atlas* atlas, float scale = 1);
|
||||||
@ -59,20 +58,21 @@ public:
|
|||||||
|
|
||||||
virtual void update (float deltaTime);
|
virtual void update (float deltaTime);
|
||||||
|
|
||||||
void addAnimationState (AnimationStateData* stateData = 0);
|
void setAnimationStateData (AnimationStateData* stateData);
|
||||||
void setAnimationStateData (AnimationStateData* stateData, int stateIndex = 0);
|
void setMix (const char* fromAnimation, const char* toAnimation, float duration);
|
||||||
AnimationState* getAnimationState (int stateIndex = 0);
|
|
||||||
void setMix (const char* fromAnimation, const char* toAnimation, float duration, int stateIndex = 0);
|
TrackEntry* setAnimation (int trackIndex, const char* name, bool loop);
|
||||||
void setAnimation (const char* name, bool loop, int stateIndex = 0);
|
TrackEntry* addAnimation (int trackIndex, const char* name, bool loop, float delay = 0);
|
||||||
void addAnimation (const char* name, bool loop, float delay = 0, int stateIndex = 0);
|
TrackEntry* getCurrent (int trackIndex = 0);
|
||||||
void clearAnimation (int stateIndex = 0);
|
void clearAnimation ();
|
||||||
|
void clearAnimation (int trackIndex = 0);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CCSkeletonAnimation ();
|
CCSkeletonAnimation ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef CCSkeleton super;
|
typedef CCSkeleton super;
|
||||||
std::vector<AnimationStateData*> stateDatas;
|
bool ownsAnimationStateData;
|
||||||
|
|
||||||
void initialize ();
|
void initialize ();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -95,7 +95,7 @@ void spineboy () {
|
|||||||
Slot* headSlot = Skeleton_findSlot(skeleton, "head");
|
Slot* headSlot = Skeleton_findSlot(skeleton, "head");
|
||||||
|
|
||||||
drawable->state->listener = callback;
|
drawable->state->listener = callback;
|
||||||
if (true) {
|
if (false) {
|
||||||
AnimationState_setAnimationByName(drawable->state, 0, "drawOrder", true);
|
AnimationState_setAnimationByName(drawable->state, 0, "drawOrder", true);
|
||||||
} else {
|
} else {
|
||||||
AnimationState_setAnimationByName(drawable->state, 0, "walk", true);
|
AnimationState_setAnimationByName(drawable->state, 0, "walk", true);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user