summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
authorHearto Lazor <heartolazor@gmail.com>2016-03-31 18:23:16 -0300
committerHearto Lazor <heartolazor@gmail.com>2016-03-31 18:23:16 -0300
commit995890d5b29fc0dc4eca66d9f11e1e3f8f275ae0 (patch)
tree636fb6a90691bc8303619ee33ac0042db0e69f62 /scene/main
parent8708a284f7b5390a48ea2fd95848f60cc40d0bf0 (diff)
Now the timer could be paused
pause with: set_active(true/false) is paused with: is_active()
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/timer.cpp26
-rw-r--r--scene/main/timer.h4
2 files changed, 27 insertions, 3 deletions
diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp
index 73458e03c0..7d9bbd7f4f 100644
--- a/scene/main/timer.cpp
+++ b/scene/main/timer.cpp
@@ -121,6 +121,20 @@ void Timer::stop() {
autostart=false;
}
+
+void Timer::set_active(bool p_active) {
+ if (active == p_active)
+ return;
+
+ active = p_active;
+ _set_process(processing);
+
+}
+
+bool Timer::is_active() const {
+ return active;
+}
+
float Timer::get_time_left() const {
return time_left >0 ? time_left : 0;
@@ -157,9 +171,10 @@ Timer::TimerProcessMode Timer::get_timer_process_mode() const{
void Timer::_set_process(bool p_process, bool p_force)
{
switch (timer_process_mode) {
- case TIMER_PROCESS_FIXED: set_fixed_process(p_process); break;
- case TIMER_PROCESS_IDLE: set_process(p_process); break;
+ case TIMER_PROCESS_FIXED: set_fixed_process(p_process && active); break;
+ case TIMER_PROCESS_IDLE: set_process(p_process && active); break;
}
+ processing = p_process;
}
void Timer::_bind_methods() {
@@ -176,6 +191,9 @@ void Timer::_bind_methods() {
ObjectTypeDB::bind_method(_MD("start"),&Timer::start);
ObjectTypeDB::bind_method(_MD("stop"),&Timer::stop);
+ ObjectTypeDB::bind_method(_MD("set_active", "active"), &Timer::set_active);
+ ObjectTypeDB::bind_method(_MD("is_active"), &Timer::is_active);
+
ObjectTypeDB::bind_method(_MD("get_time_left"),&Timer::get_time_left);
ObjectTypeDB::bind_method(_MD("set_timer_process_mode", "mode"), &Timer::set_timer_process_mode);
@@ -198,5 +216,7 @@ Timer::Timer() {
autostart=false;
wait_time=1;
one_shot=false;
- time_left=-1;
+ time_left = -1;
+ processing = false;
+ active = true;
}
diff --git a/scene/main/timer.h b/scene/main/timer.h
index 0baea76fad..688be6e4f2 100644
--- a/scene/main/timer.h
+++ b/scene/main/timer.h
@@ -38,6 +38,8 @@ class Timer : public Node {
float wait_time;
bool one_shot;
bool autostart;
+ bool processing;
+ bool active;
double time_left;
protected:
@@ -62,6 +64,8 @@ public:
void start();
void stop();
+ void set_active(bool p_active);
+ bool is_active() const;
float get_time_left() const;