add arriving last frame event

This commit is contained in:
kaile.yin 2014-10-23 17:38:04 +08:00
parent e7de544231
commit 0f184a4982
2 changed files with 21 additions and 0 deletions

View File

@ -78,6 +78,7 @@ ActionTimeline::ActionTimeline()
, _startFrame(0)
, _endFrame(0)
, _frameEventListener(nullptr)
, _lastFrameListener(nullptr)
{
}
@ -186,6 +187,9 @@ void ActionTimeline::step(float delta)
if(_time > _endFrame * _frameInternal)
{
if(_lastFrameListener != nullptr)
_lastFrameListener();
_playing = _loop;
if(!_playing)
_time = _endFrame * _frameInternal;
@ -272,6 +276,15 @@ void ActionTimeline::clearFrameEventCallFunc()
_frameEventListener = nullptr;
}
void ActionTimeline::setLastFrameCallFunc(std::function<void()> listener)
{
_lastFrameListener = listener;
}
void ActionTimeline::clearLastFrameCallFunc()
{
_lastFrameListener = nullptr;
}
void ActionTimeline::emitFrameEvent(Frame* frame)
{
@ -283,6 +296,9 @@ void ActionTimeline::emitFrameEvent(Frame* frame)
void ActionTimeline::gotoFrame(int frameIndex)
{
if(_target == nullptr)
return;
ssize_t size = _timelineList.size();
for(ssize_t i = 0; i < size; i++)
{

View File

@ -129,6 +129,10 @@ public:
void setFrameEventCallFunc(std::function<void(Frame *)> listener);
void clearFrameEventCallFunc();
/** Last frame callback will call when arriving last frame */
void setLastFrameCallFunc(std::function<void()> listener);
void clearLastFrameCallFunc();
/** Inherit from Action. */
/** Returns a clone of ActionTimeline */
@ -163,6 +167,7 @@ protected:
bool _loop;
std::function<void(Frame*)> _frameEventListener;
std::function<void()> _lastFrameListener;
};
NS_TIMELINE_END