Magic_Game/core/Action/Action.cpp

219 lines
4.2 KiB
C++
Raw Normal View History

2017-10-19 00:50:04 +08:00
#include "..\eactions.h"
2018-03-06 09:56:17 +08:00
#include "..\emanagers.h"
2017-10-19 00:50:04 +08:00
e2d::Action::Action()
2018-01-30 16:45:38 +08:00
: m_bRunning(false)
, m_bEnding(false)
, m_bInit(false)
, m_pTarget(nullptr)
, m_pParentScene(nullptr)
, m_fLast(0)
2017-10-19 00:50:04 +08:00
{
2018-03-06 09:56:17 +08:00
ActionManager::__add(this);
2017-10-19 00:50:04 +08:00
}
e2d::Action::~Action()
2017-10-19 00:50:04 +08:00
{
2018-03-06 09:56:17 +08:00
ActionManager::__remove(this);
2017-10-19 00:50:04 +08:00
}
bool e2d::Action::isRunning()
2017-10-19 00:50:04 +08:00
{
return m_bRunning;
2017-10-19 00:50:04 +08:00
}
bool e2d::Action::_isEnding()
2017-10-19 00:50:04 +08:00
{
return m_bEnding;
}
2018-03-06 09:56:17 +08:00
void e2d::Action::setTarget(Node* pTarget)
2017-10-19 00:50:04 +08:00
{
2018-03-06 09:56:17 +08:00
if (pTarget)
{
m_bRunning = true;
m_pTarget = pTarget;
this->reset();
}
2017-10-19 00:50:04 +08:00
}
void e2d::Action::resume()
2017-10-19 00:50:04 +08:00
{
m_bRunning = true;
m_fLast = Time::getTotalTime();
2017-10-19 00:50:04 +08:00
}
void e2d::Action::pause()
2017-10-19 00:50:04 +08:00
{
m_bRunning = false;
}
void e2d::Action::stop()
2017-10-19 00:50:04 +08:00
{
m_bEnding = true;
}
2018-03-06 09:56:17 +08:00
e2d::String e2d::Action::getName() const
{
return m_sName;
}
void e2d::Action::setName(String name)
2018-03-06 09:56:17 +08:00
{
m_sName = name;
}
e2d::Action * e2d::Action::reverse() const
2017-10-19 00:50:04 +08:00
{
ASSERT(false, "Action cannot be reversed!");
2017-10-19 00:50:04 +08:00
return nullptr;
}
e2d::Node * e2d::Action::getTarget()
2017-10-19 00:50:04 +08:00
{
return m_pTarget;
}
void e2d::Action::_init()
2017-10-19 00:50:04 +08:00
{
m_bInit = true;
2017-10-21 19:09:31 +08:00
// <20><>¼<EFBFBD><C2BC>ǰʱ<C7B0><CAB1>
m_fLast = Time::getTotalTime();
2017-10-19 00:50:04 +08:00
}
void e2d::Action::_update()
2017-11-03 12:51:01 +08:00
{
if (!m_bInit)
{
_init();
}
}
void e2d::Action::reset()
2017-10-19 00:50:04 +08:00
{
m_bInit = false;
m_bEnding = false;
m_fLast = Time::getTotalTime();
}
void e2d::Action::_resetTime()
{
m_fLast = Time::getTotalTime();
2017-10-19 00:50:04 +08:00
}
e2d::ActionMoveBy * e2d::action::MoveBy(double duration, Vector vector)
{
return new (std::nothrow) ActionMoveBy(duration, vector);
}
e2d::ActionMoveTo * e2d::action::MoveTo(double duration, Point pos)
{
return new (std::nothrow) ActionMoveTo(duration, pos);
}
e2d::ActionScaleBy * e2d::action::ScaleBy(double duration, double scale)
{
return new (std::nothrow) ActionScaleBy(duration, scale);
}
e2d::ActionScaleBy * e2d::action::ScaleBy(double duration, double scaleX, double scaleY)
{
return new (std::nothrow) ActionScaleBy(duration, scaleX, scaleY);
}
e2d::ActionScaleTo * e2d::action::ScaleTo(double duration, double scale)
{
return new (std::nothrow) ActionScaleTo(duration, scale);
}
e2d::ActionScaleTo * e2d::action::ScaleTo(double duration, double scaleX, double scaleY)
{
return new (std::nothrow) ActionScaleTo(duration, scaleX, scaleY);
}
e2d::ActionOpacityBy * e2d::action::OpacityBy(double duration, double opacity)
{
return new (std::nothrow) ActionOpacityBy(duration, opacity);
}
e2d::ActionOpacityTo * e2d::action::OpacityTo(double duration, double opacity)
{
return new (std::nothrow) ActionOpacityTo(duration, opacity);
}
e2d::ActionFadeIn * e2d::action::FadeIn(double duration)
{
return new (std::nothrow) ActionFadeIn(duration);
}
e2d::ActionFadeOut * e2d::action::FadeOut(double duration)
{
return new (std::nothrow) ActionFadeOut(duration);
}
e2d::ActionRotateBy * e2d::action::RotateBy(double duration, double rotation)
{
return new (std::nothrow) ActionRotateBy(duration, rotation);
}
e2d::ActionRotateTo * e2d::action::RotateTo(double duration, double rotation)
{
return new (std::nothrow) ActionRotateTo(duration, rotation);
}
e2d::ActionTwo * e2d::action::Two(Action * pActionFirst, Action * pActionSecond, bool bAtSameTime)
{
return new (std::nothrow) ActionTwo(pActionFirst, pActionSecond, bAtSameTime);
}
e2d::ActionSequence * e2d::action::Sequence(int number, Action * action1, ...)
{
auto action = new (std::nothrow) ActionSequence();
if (action)
{
Action ** ppAction = &action1;
while (number > 0)
{
ASSERT((*ppAction) != nullptr, "ActionSequence NULL pointer exception!");
action->add(*ppAction);
ppAction++;
number--;
}
}
return action;
}
e2d::ActionDelay * e2d::action::Delay(double duration)
{
return new (std::nothrow) ActionDelay(duration);
}
e2d::ActionLoop * e2d::action::Loop(Action * action, int times)
{
return new (std::nothrow) ActionLoop(action, times);
}
e2d::Animation * e2d::action::Animate(double interval, int number, Image * frame, ...)
{
auto animation = new (std::nothrow) Animation(interval);
if (animation)
{
Image ** ppImage = &frame;
while (number > 0)
{
ASSERT((*ppImage) != nullptr, "Animation NULL pointer exception!");
animation->addKeyframe(*ppImage);
ppImage++;
number--;
}
}
return animation;
}
e2d::ActionFunc * e2d::action::Func(Function func)
{
return new (std::nothrow) ActionFunc(func);
}