mirror of https://github.com/axmolengine/axmol.git
support animation list
This commit is contained in:
parent
92584bbc7f
commit
70052b2a3f
|
@ -91,6 +91,17 @@ bool ActionTimeline::init()
|
|||
return true;
|
||||
}
|
||||
|
||||
void ActionTimeline::play(std::string name, bool loop)
|
||||
{
|
||||
if(_indexes.find(name) == _indexes.end())
|
||||
{
|
||||
CCLOG("Cann't find action indexes for %s.", name.c_str());
|
||||
}
|
||||
|
||||
ActionIndexes& indexes = _indexes[name];
|
||||
gotoFrameAndPlay(indexes.startIndex, indexes.endIndex, loop);
|
||||
}
|
||||
|
||||
void ActionTimeline::gotoFrameAndPlay(int startIndex)
|
||||
{
|
||||
gotoFrameAndPlay(startIndex, true);
|
||||
|
@ -266,6 +277,28 @@ void ActionTimeline::removeTimeline(Timeline* timeline)
|
|||
}
|
||||
}
|
||||
|
||||
void ActionTimeline::addIndexes(const ActionIndexes& indexes)
|
||||
{
|
||||
if(_indexes.find(indexes.name) != _indexes.end())
|
||||
{
|
||||
CCLOG("ActionIndexes (%s) already exsists.", indexes.name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
_indexes[indexes.name] = indexes;
|
||||
}
|
||||
|
||||
void ActionTimeline::removeIndexes(std::string name)
|
||||
{
|
||||
if(_indexes.find(name) == _indexes.end())
|
||||
{
|
||||
CCLOG("ActionIndexes %s don't exsists.", name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
_indexes.erase(name);
|
||||
}
|
||||
|
||||
void ActionTimeline::setFrameEventCallFunc(std::function<void(Frame *)> listener)
|
||||
{
|
||||
_frameEventListener = listener;
|
||||
|
|
|
@ -31,6 +31,13 @@ THE SOFTWARE.
|
|||
|
||||
NS_TIMELINE_BEGIN
|
||||
|
||||
struct ActionIndexes
|
||||
{
|
||||
std::string name;
|
||||
int startIndex;
|
||||
int endIndex;
|
||||
};
|
||||
|
||||
class CC_STUDIO_DLL ActionTimelineData : public cocos2d::Ref
|
||||
{
|
||||
public:
|
||||
|
@ -57,6 +64,8 @@ public:
|
|||
virtual ~ActionTimeline();
|
||||
|
||||
virtual bool init();
|
||||
|
||||
virtual void play(std::string name, bool loop);
|
||||
|
||||
/** Goto the specified frame index, and start playing from this index.
|
||||
* @param startIndex The animation will play from this index.
|
||||
|
@ -88,6 +97,7 @@ public:
|
|||
* @param startIndex The animation will pause at this index.
|
||||
*/
|
||||
virtual void gotoFrameAndPause(int startIndex);
|
||||
|
||||
|
||||
/** Pause the animation. */
|
||||
virtual void pause();
|
||||
|
@ -122,7 +132,11 @@ public:
|
|||
/** add Timeline to ActionTimeline */
|
||||
virtual void addTimeline(Timeline* timeline);
|
||||
virtual void removeTimeline(Timeline* timeline);
|
||||
|
||||
|
||||
/** add ActionIndexes */
|
||||
virtual void addIndexes(const ActionIndexes& indexes);
|
||||
virtual void removeIndexes(std::string name);
|
||||
|
||||
virtual const cocos2d::Vector<Timeline*>& getTimelines() const { return _timelineList; }
|
||||
|
||||
/** Set ActionTimeline's frame event callback function */
|
||||
|
@ -168,6 +182,7 @@ protected:
|
|||
|
||||
std::function<void(Frame*)> _frameEventListener;
|
||||
std::function<void()> _lastFrameListener;
|
||||
std::map<std::string, ActionIndexes> _indexes;
|
||||
};
|
||||
|
||||
NS_TIMELINE_END
|
||||
|
|
|
@ -439,6 +439,22 @@ ActionTimeline* ActionTimelineCache::loadAnimationActionWithFlatBuffersFile(cons
|
|||
float speed = nodeAction->speed();
|
||||
action->setTimeSpeed(speed);
|
||||
|
||||
auto animationList = nodeAction->animationList();
|
||||
if(animationList)
|
||||
{
|
||||
auto animationLength = animationList->size();
|
||||
for (int i = 0; i < animationLength; i++)
|
||||
{
|
||||
auto animationFlatBuf = animationList->Get(i);
|
||||
ActionIndexes indexes;
|
||||
indexes.startIndex = animationFlatBuf->startIndex();
|
||||
indexes.endIndex = animationFlatBuf->endIndex();
|
||||
indexes.name = animationFlatBuf->name()->c_str();
|
||||
|
||||
action->addIndexes(indexes);
|
||||
}
|
||||
}
|
||||
|
||||
auto timelines = nodeAction->timeLines();
|
||||
int timelineLength = timelines->size();
|
||||
for (int i = 0; i < timelineLength; i++)
|
||||
|
|
|
@ -1686,44 +1686,97 @@ inline flatbuffers::Offset<ComAudioOptions> CreateComAudioOptions(flatbuffers::F
|
|||
return builder_.Finish();
|
||||
}
|
||||
|
||||
|
||||
struct AnimationInfo : private flatbuffers::Table {
|
||||
const flatbuffers::String *name() const { return GetPointer<const flatbuffers::String *>(4); }
|
||||
int32_t startIndex() const { return GetField<int32_t>(6, 0); }
|
||||
int32_t endIndex() const { return GetField<int32_t>(8, 0); }
|
||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* name */) &&
|
||||
verifier.Verify(name()) &&
|
||||
VerifyField<int32_t>(verifier, 6 /* startIndex */) &&
|
||||
VerifyField<int32_t>(verifier, 8 /* endIndex */) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct AnimationInfoBuilder {
|
||||
flatbuffers::FlatBufferBuilder &fbb_;
|
||||
flatbuffers::uoffset_t start_;
|
||||
void add_name(flatbuffers::Offset<flatbuffers::String> name) { fbb_.AddOffset(4, name); }
|
||||
void add_startIndex(int32_t startIndex) { fbb_.AddElement<int32_t>(6, startIndex, 0); }
|
||||
void add_endIndex(int32_t endIndex) { fbb_.AddElement<int32_t>(8, endIndex, 0); }
|
||||
AnimationInfoBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
||||
AnimationInfoBuilder &operator=(const AnimationInfoBuilder &);
|
||||
flatbuffers::Offset<AnimationInfo> Finish() {
|
||||
auto o = flatbuffers::Offset<AnimationInfo>(fbb_.EndTable(start_, 3));
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline flatbuffers::Offset<AnimationInfo> CreateAnimationInfo(flatbuffers::FlatBufferBuilder &_fbb,
|
||||
flatbuffers::Offset<flatbuffers::String> name = 0,
|
||||
int32_t startIndex = 0,
|
||||
int32_t endIndex = 0) {
|
||||
AnimationInfoBuilder builder_(_fbb);
|
||||
builder_.add_endIndex(endIndex);
|
||||
builder_.add_startIndex(startIndex);
|
||||
builder_.add_name(name);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
struct NodeAction : private flatbuffers::Table {
|
||||
int32_t duration() const { return GetField<int32_t>(4, 0); }
|
||||
float speed() const { return GetField<float>(6, 0); }
|
||||
const flatbuffers::Vector<flatbuffers::Offset<TimeLine>> *timeLines() const { return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<TimeLine>> *>(8); }
|
||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<int32_t>(verifier, 4 /* duration */) &&
|
||||
VerifyField<float>(verifier, 6 /* speed */) &&
|
||||
VerifyField<flatbuffers::uoffset_t>(verifier, 8 /* timeLines */) &&
|
||||
verifier.Verify(timeLines()) &&
|
||||
verifier.VerifyVectorOfTables(timeLines()) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
int32_t duration() const { return GetField<int32_t>(4, 0); }
|
||||
float speed() const { return GetField<float>(6, 0); }
|
||||
const flatbuffers::Vector<flatbuffers::Offset<TimeLine>> *timeLines() const { return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<TimeLine>> *>(8); }
|
||||
const flatbuffers::Vector<flatbuffers::Offset<AnimationInfo>> *animationList() const { return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<AnimationInfo>> *>(10); }
|
||||
const flatbuffers::String *currentAnimationName() const { return GetPointer<const flatbuffers::String *>(12); }
|
||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<int32_t>(verifier, 4 /* duration */) &&
|
||||
VerifyField<float>(verifier, 6 /* speed */) &&
|
||||
VerifyField<flatbuffers::uoffset_t>(verifier, 8 /* timeLines */) &&
|
||||
verifier.Verify(timeLines()) &&
|
||||
verifier.VerifyVectorOfTables(timeLines()) &&
|
||||
VerifyField<flatbuffers::uoffset_t>(verifier, 10 /* animationList */) &&
|
||||
verifier.Verify(animationList()) &&
|
||||
verifier.VerifyVectorOfTables(animationList()) &&
|
||||
VerifyField<flatbuffers::uoffset_t>(verifier, 12 /* currentAnimationName */) &&
|
||||
verifier.Verify(currentAnimationName()) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct NodeActionBuilder {
|
||||
flatbuffers::FlatBufferBuilder &fbb_;
|
||||
flatbuffers::uoffset_t start_;
|
||||
void add_duration(int32_t duration) { fbb_.AddElement<int32_t>(4, duration, 0); }
|
||||
void add_speed(float speed) { fbb_.AddElement<float>(6, speed, 0); }
|
||||
void add_timeLines(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<TimeLine>>> timeLines) { fbb_.AddOffset(8, timeLines); }
|
||||
NodeActionBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
||||
NodeActionBuilder &operator=(const NodeActionBuilder &);
|
||||
flatbuffers::Offset<NodeAction> Finish() {
|
||||
auto o = flatbuffers::Offset<NodeAction>(fbb_.EndTable(start_, 3));
|
||||
return o;
|
||||
}
|
||||
flatbuffers::FlatBufferBuilder &fbb_;
|
||||
flatbuffers::uoffset_t start_;
|
||||
void add_duration(int32_t duration) { fbb_.AddElement<int32_t>(4, duration, 0); }
|
||||
void add_speed(float speed) { fbb_.AddElement<float>(6, speed, 0); }
|
||||
void add_timeLines(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<TimeLine>>> timeLines) { fbb_.AddOffset(8, timeLines); }
|
||||
void add_animationList(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<AnimationInfo>>> animationList) { fbb_.AddOffset(10, animationList); }
|
||||
void add_currentAnimationName(flatbuffers::Offset<flatbuffers::String> currentAnimationName) { fbb_.AddOffset(12, currentAnimationName); }
|
||||
NodeActionBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
||||
NodeActionBuilder &operator=(const NodeActionBuilder &);
|
||||
flatbuffers::Offset<NodeAction> Finish() {
|
||||
auto o = flatbuffers::Offset<NodeAction>(fbb_.EndTable(start_, 5));
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline flatbuffers::Offset<NodeAction> CreateNodeAction(flatbuffers::FlatBufferBuilder &_fbb,
|
||||
int32_t duration = 0,
|
||||
float speed = 0,
|
||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<TimeLine>>> timeLines = 0) {
|
||||
NodeActionBuilder builder_(_fbb);
|
||||
builder_.add_timeLines(timeLines);
|
||||
builder_.add_speed(speed);
|
||||
builder_.add_duration(duration);
|
||||
return builder_.Finish();
|
||||
int32_t duration = 0,
|
||||
float speed = 0,
|
||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<TimeLine>>> timeLines = 0,
|
||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<AnimationInfo>>> animationList = 0,
|
||||
flatbuffers::Offset<flatbuffers::String> currentAnimationName = 0) {
|
||||
NodeActionBuilder builder_(_fbb);
|
||||
builder_.add_currentAnimationName(currentAnimationName);
|
||||
builder_.add_animationList(animationList);
|
||||
builder_.add_timeLines(timeLines);
|
||||
builder_.add_speed(speed);
|
||||
builder_.add_duration(duration);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
struct TimeLine : private flatbuffers::Table {
|
||||
|
|
|
@ -199,9 +199,12 @@ void TestActionTimeline::onEnter()
|
|||
|
||||
Node* node = CSLoader::createNode("ActionTimeline/DemoPlayer.csb");
|
||||
ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/DemoPlayer.csb");
|
||||
|
||||
ActionIndexes indexes = {"walk", 0, 40};
|
||||
action->addIndexes(indexes);
|
||||
|
||||
node->runAction(action);
|
||||
action->gotoFrameAndPlay(0, 40, true);
|
||||
action->play("walk", true);
|
||||
|
||||
node->setScale(0.2f);
|
||||
node->setPosition(VisibleRect::center());
|
||||
|
|
Loading…
Reference in New Issue