Magic_Game/core/Action/ActionLoop.cpp

68 lines
998 B
C++
Raw Normal View History

2018-04-21 21:24:46 +08:00
#include "..\e2daction.h"
#include "..\e2dmanager.h"
e2d::ActionLoop::ActionLoop(Action * action, int times /* = -1 */)
2017-11-03 12:51:01 +08:00
: m_pAction(action)
, m_nTimes(0)
, m_nTotalTimes(times)
{
ASSERT(m_pAction != nullptr, "ActionLoop NULL pointer exception!");
2017-11-03 12:51:01 +08:00
m_pAction->retain();
}
e2d::ActionLoop::~ActionLoop()
{
}
e2d::ActionLoop * e2d::ActionLoop::clone() const
{
return new ActionLoop(m_pAction->clone());
}
void e2d::ActionLoop::_init()
{
Action::_init();
2018-02-06 15:34:47 +08:00
m_pAction->m_pTarget = m_pTarget;
2017-11-03 12:51:01 +08:00
m_pAction->_init();
}
void e2d::ActionLoop::_update()
{
Action::_update();
2017-11-03 12:51:01 +08:00
if (m_nTimes == m_nTotalTimes)
{
2017-11-03 12:51:01 +08:00
this->stop();
return;
}
m_pAction->_update();
2017-11-03 12:51:01 +08:00
if (m_pAction->_isEnding())
{
m_nTimes++;
Action::reset();
2018-02-06 15:34:47 +08:00
m_pAction->reset();
}
}
void e2d::ActionLoop::reset()
{
Action::reset();
2017-11-03 12:51:01 +08:00
2018-02-06 15:34:47 +08:00
m_pAction->reset();
2017-11-03 12:51:01 +08:00
m_nTimes = 0;
}
void e2d::ActionLoop::destroy()
{
Action::destroy();
SafeRelease(&m_pAction);
}
void e2d::ActionLoop::_resetTime()
{
m_pAction->_resetTime();
}