Merge pull request #9637 from geron-cn/v3_actionline_animationlist

V3 actiontimeline animationlist
This commit is contained in:
minggo 2014-12-26 16:05:49 +08:00
commit f01cc596a3
3 changed files with 51 additions and 1 deletions

View File

@ -91,6 +91,18 @@ 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());
return;
}
ActionIndexes& indexes = _indexes[name];
gotoFrameAndPlay(indexes.startIndex, indexes.endIndex, loop);
}
void ActionTimeline::gotoFrameAndPlay(int startIndex)
{
gotoFrameAndPlay(startIndex, true);
@ -266,6 +278,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;

View File

@ -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:
@ -58,6 +65,8 @@ public:
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.
*/
@ -89,6 +98,7 @@ public:
*/
virtual void gotoFrameAndPause(int startIndex);
/** Pause the animation. */
virtual void pause();
/** Resume the animation. */
@ -123,6 +133,10 @@ public:
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

View File

@ -439,6 +439,7 @@ ActionTimeline* ActionTimelineCache::loadAnimationActionWithFlatBuffersFile(cons
float speed = nodeAction->speed();
action->setTimeSpeed(speed);
auto timelines = nodeAction->timeLines();
int timelineLength = timelines->size();
for (int i = 0; i < timelineLength; i++)