Magic_Game/core/actions/Delay.cpp

47 lines
645 B
C++
Raw Normal View History

#include "..\e2daction.h"
2018-07-28 20:06:27 +08:00
e2d::Delay::Delay(float duration)
2018-09-04 22:42:34 +08:00
: delta_(0)
, delay_(std::max(duration, 0.f))
{
}
2018-09-04 22:42:34 +08:00
e2d::Delay * e2d::Delay::Clone() const
{
2018-09-04 22:42:34 +08:00
return new (e2d::autorelease) Delay(delay_);
}
2018-09-04 22:42:34 +08:00
e2d::Delay * e2d::Delay::Reverse() const
2018-05-14 00:36:01 +08:00
{
2018-09-04 22:42:34 +08:00
return new (e2d::autorelease) Delay(delay_);
2018-05-14 00:36:01 +08:00
}
2018-09-04 22:42:34 +08:00
void e2d::Delay::Reset()
{
2018-09-04 22:42:34 +08:00
Action::Reset();
delta_ = 0;
}
2018-09-04 22:42:34 +08:00
void e2d::Delay::Init()
{
2018-09-04 22:42:34 +08:00
Action::Init();
}
2018-09-04 22:42:34 +08:00
void e2d::Delay::Update()
{
2018-09-04 22:42:34 +08:00
Action::Update();
2018-05-10 14:03:54 +08:00
2018-09-04 22:42:34 +08:00
delta_ = (Time::Now() - started_).Seconds();
2018-09-04 22:42:34 +08:00
if (delta_ >= delay_)
{
2018-09-04 22:42:34 +08:00
this->Stop();
}
}
2018-09-04 22:42:34 +08:00
void e2d::Delay::ResetTime()
{
2018-09-04 22:42:34 +08:00
Action::ResetTime();
started_ = Time::Now() - Duration(delta_);
}