Skip to content

Commit

Permalink
Merge pull request cocos2d#9637 from geron-cn/v3_actionline_animation…
Browse files Browse the repository at this point in the history
…list

V3 actiontimeline animationlist
  • Loading branch information
minggo committed Dec 26, 2014
2 parents 275de89 + 70eef1f commit f01cc59
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -57,6 +64,8 @@ class CC_STUDIO_DLL ActionTimeline : public cocos2d::Action
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.
Expand Down Expand Up @@ -88,6 +97,7 @@ class CC_STUDIO_DLL ActionTimeline : public cocos2d::Action
* @param startIndex The animation will pause at this index.
*/
virtual void gotoFrameAndPause(int startIndex);


/** Pause the animation. */
virtual void pause();
Expand Down Expand Up @@ -122,7 +132,11 @@ class CC_STUDIO_DLL ActionTimeline : public cocos2d::Action
/** 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 */
Expand Down Expand Up @@ -168,6 +182,7 @@ class CC_STUDIO_DLL ActionTimeline : public cocos2d::Action

std::function<void(Frame*)> _frameEventListener;
std::function<void()> _lastFrameListener;
std::map<std::string, ActionIndexes> _indexes;
};

NS_TIMELINE_END
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down

0 comments on commit f01cc59

Please sign in to comment.