update Ticker

This commit is contained in:
Nomango 2020-05-20 10:16:54 +08:00
parent 86bb0e4239
commit 01ce68accb
2 changed files with 11 additions and 7 deletions

View File

@ -37,11 +37,15 @@ TickerPtr Ticker::Create(Duration interval, int times)
Ticker::Ticker()
: ticked_times_(0)
, total_times_(0)
, is_paused_(false)
{
}
bool Ticker::Tick()
{
if (is_paused_)
return false;
if (!timer_)
timer_ = Timer::Create();
@ -55,6 +59,9 @@ bool Ticker::Tick()
bool Ticker::Tick(Duration dt)
{
if (is_paused_)
return false;
if (ticked_times_ == total_times_)
return false;

View File

@ -100,6 +100,7 @@ public:
void Reset();
private:
bool is_paused_;
int ticked_times_;
int total_times_;
Duration interval_;
@ -111,21 +112,17 @@ private:
inline void Ticker::Pause()
{
KGE_ASSERT(timer_);
timer_->Pause();
is_paused_ = true;
}
inline void Ticker::Resume()
{
KGE_ASSERT(timer_);
timer_->Resume();
is_paused_ = false;
}
inline bool Ticker::IsPausing() const
{
if (timer_)
return timer_->IsPausing();
return true;
return is_paused_;
}
inline int Ticker::GetTickedTimes() const