Magic_Game/core/Action/ActionLoop.cpp

68 lines
989 B
C++
Raw Normal View History

2018-04-21 21:24:46 +08:00
#include "..\e2daction.h"
#include "..\e2dmanager.h"
e2d::ActionLoop::ActionLoop(ActionBase * action, int times /* = -1 */)
2018-05-08 17:40:36 +08:00
: _pAction(action)
, _nTimes(0)
, _nTotalTimes(times)
{
2018-05-08 17:40:36 +08:00
ASSERT(_pAction, "ActionLoop NULL pointer exception!");
_pAction->retain();
}
e2d::ActionLoop::~ActionLoop()
{
}
e2d::ActionLoop * e2d::ActionLoop::clone() const
{
2018-05-08 17:40:36 +08:00
return new ActionLoop(_pAction->clone());
}
void e2d::ActionLoop::_init()
{
ActionBase::_init();
2018-05-08 17:40:36 +08:00
_pAction->_pTarget = _pTarget;
_pAction->_init();
}
void e2d::ActionLoop::_update()
{
ActionBase::_update();
2018-05-08 17:40:36 +08:00
if (_nTimes == _nTotalTimes)
{
2017-11-03 12:51:01 +08:00
this->stop();
return;
}
2018-05-08 17:40:36 +08:00
_pAction->_update();
2017-11-03 12:51:01 +08:00
2018-05-08 17:40:36 +08:00
if (_pAction->_isDone())
2017-11-03 12:51:01 +08:00
{
2018-05-08 17:40:36 +08:00
_nTimes++;
2017-11-03 12:51:01 +08:00
ActionBase::reset();
2018-05-08 17:40:36 +08:00
_pAction->reset();
}
}
void e2d::ActionLoop::reset()
{
ActionBase::reset();
2017-11-03 12:51:01 +08:00
2018-05-08 17:40:36 +08:00
_pAction->reset();
_nTimes = 0;
}
void e2d::ActionLoop::destroy()
{
ActionBase::destroy();
2018-05-08 17:40:36 +08:00
SafeRelease(&_pAction);
}
void e2d::ActionLoop::_resetTime()
{
2018-05-08 17:40:36 +08:00
_pAction->_resetTime();
}