mirror of https://github.com/axmolengine/axmol.git
Merge pull request #9637 from geron-cn/v3_actionline_animationlist
V3 actiontimeline animationlist
This commit is contained in:
commit
f01cc596a3
|
@ -91,6 +91,18 @@ bool ActionTimeline::init()
|
||||||
return true;
|
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)
|
void ActionTimeline::gotoFrameAndPlay(int startIndex)
|
||||||
{
|
{
|
||||||
gotoFrameAndPlay(startIndex, true);
|
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)
|
void ActionTimeline::setFrameEventCallFunc(std::function<void(Frame *)> listener)
|
||||||
{
|
{
|
||||||
_frameEventListener = listener;
|
_frameEventListener = listener;
|
||||||
|
|
|
@ -31,6 +31,13 @@ THE SOFTWARE.
|
||||||
|
|
||||||
NS_TIMELINE_BEGIN
|
NS_TIMELINE_BEGIN
|
||||||
|
|
||||||
|
struct ActionIndexes
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
int startIndex;
|
||||||
|
int endIndex;
|
||||||
|
};
|
||||||
|
|
||||||
class CC_STUDIO_DLL ActionTimelineData : public cocos2d::Ref
|
class CC_STUDIO_DLL ActionTimelineData : public cocos2d::Ref
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -57,6 +64,8 @@ public:
|
||||||
virtual ~ActionTimeline();
|
virtual ~ActionTimeline();
|
||||||
|
|
||||||
virtual bool init();
|
virtual bool init();
|
||||||
|
|
||||||
|
virtual void play(std::string name, bool loop);
|
||||||
|
|
||||||
/** Goto the specified frame index, and start playing from this index.
|
/** Goto the specified frame index, and start playing from this index.
|
||||||
* @param startIndex The animation will play 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.
|
* @param startIndex The animation will pause at this index.
|
||||||
*/
|
*/
|
||||||
virtual void gotoFrameAndPause(int startIndex);
|
virtual void gotoFrameAndPause(int startIndex);
|
||||||
|
|
||||||
|
|
||||||
/** Pause the animation. */
|
/** Pause the animation. */
|
||||||
virtual void pause();
|
virtual void pause();
|
||||||
|
@ -122,7 +132,11 @@ public:
|
||||||
/** add Timeline to ActionTimeline */
|
/** add Timeline to ActionTimeline */
|
||||||
virtual void addTimeline(Timeline* timeline);
|
virtual void addTimeline(Timeline* timeline);
|
||||||
virtual void removeTimeline(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; }
|
virtual const cocos2d::Vector<Timeline*>& getTimelines() const { return _timelineList; }
|
||||||
|
|
||||||
/** Set ActionTimeline's frame event callback function */
|
/** Set ActionTimeline's frame event callback function */
|
||||||
|
@ -168,6 +182,7 @@ protected:
|
||||||
|
|
||||||
std::function<void(Frame*)> _frameEventListener;
|
std::function<void(Frame*)> _frameEventListener;
|
||||||
std::function<void()> _lastFrameListener;
|
std::function<void()> _lastFrameListener;
|
||||||
|
std::map<std::string, ActionIndexes> _indexes;
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_TIMELINE_END
|
NS_TIMELINE_END
|
||||||
|
|
|
@ -439,6 +439,7 @@ ActionTimeline* ActionTimelineCache::loadAnimationActionWithFlatBuffersFile(cons
|
||||||
float speed = nodeAction->speed();
|
float speed = nodeAction->speed();
|
||||||
action->setTimeSpeed(speed);
|
action->setTimeSpeed(speed);
|
||||||
|
|
||||||
|
|
||||||
auto timelines = nodeAction->timeLines();
|
auto timelines = nodeAction->timeLines();
|
||||||
int timelineLength = timelines->size();
|
int timelineLength = timelines->size();
|
||||||
for (int i = 0; i < timelineLength; i++)
|
for (int i = 0; i < timelineLength; i++)
|
||||||
|
|
Loading…
Reference in New Issue