Magic_Game/core/Action/Loop.cpp

91 lines
1.1 KiB
C++
Raw Normal View History

#include "..\e2daction.h"
#include "..\e2dmanager.h"
e2d::Loop::Loop(Action * action, int times /* = -1 */)
: _action(action)
, _times(0)
, _totalTimes(times)
{
2018-05-10 14:03:54 +08:00
ASSERT(action, "Loop NULL pointer exception!");
if (action)
{
_action = action;
_action->retain();
}
}
e2d::Loop::~Loop()
{
}
e2d::Loop * e2d::Loop::clone() const
{
2018-05-10 14:03:54 +08:00
if (_action)
{
return new (std::nothrow) Loop(_action->clone());
}
else
{
return nullptr;
}
}
void e2d::Loop::_init()
{
Action::_init();
2018-05-10 14:03:54 +08:00
if (_action)
{
_action->_target = _target;
_action->_init();
}
}
void e2d::Loop::_update()
{
Action::_update();
if (_times == _totalTimes)
{
this->stop();
return;
}
2018-05-10 14:03:54 +08:00
if (_action)
{
_action->_update();
2018-05-10 14:03:54 +08:00
if (_action->_isDone())
{
_times++;
Action::reset();
_action->reset();
}
}
else
{
2018-05-10 14:03:54 +08:00
this->stop();
}
}
void e2d::Loop::reset()
{
Action::reset();
2018-05-10 14:03:54 +08:00
if (_action) _action->reset();
_times = 0;
}
void e2d::Loop::onDestroy()
{
Action::onDestroy();
2018-05-10 20:23:32 +08:00
SafeRelease(_action);
}
void e2d::Loop::_resetTime()
{
2018-05-10 14:03:54 +08:00
if (_action) _action->_resetTime();
}