Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option for tweens to ignore Engine.time_scale #100735

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/classes/Tween.xml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@
[/codeblock]
</description>
</method>
<method name="set_ignore_time_scale">
<return type="Tween" />
<param index="0" name="ignore" type="bool" default="true" />
<description>
If [param ignore] is [code]true[/code], the tween will ignore [member Engine.time_scale] and update with the real, elapsed time. This affects all [Tweener]s and their delays. Default value is [code]false[/code].
</description>
</method>
<method name="set_loops">
<return type="Tween" />
<param index="0" name="loops" type="int" default="0" />
Expand Down
10 changes: 10 additions & 0 deletions scene/animation/tween.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,15 @@ Tween::TweenPauseMode Tween::get_pause_mode() {
return pause_mode;
}

Ref<Tween> Tween::set_ignore_time_scale(bool p_ignore) {
ignore_time_scale = p_ignore;
return this;
}

bool Tween::is_ignoring_time_scale() const {
return ignore_time_scale;
}

Ref<Tween> Tween::set_parallel(bool p_parallel) {
default_parallel = p_parallel;
parallel_enabled = p_parallel;
Expand Down Expand Up @@ -451,6 +460,7 @@ void Tween::_bind_methods() {
ClassDB::bind_method(D_METHOD("bind_node", "node"), &Tween::bind_node);
ClassDB::bind_method(D_METHOD("set_process_mode", "mode"), &Tween::set_process_mode);
ClassDB::bind_method(D_METHOD("set_pause_mode", "mode"), &Tween::set_pause_mode);
ClassDB::bind_method(D_METHOD("set_ignore_time_scale", "ignore"), &Tween::set_ignore_time_scale, DEFVAL(true));

ClassDB::bind_method(D_METHOD("set_parallel", "parallel"), &Tween::set_parallel, DEFVAL(true));
ClassDB::bind_method(D_METHOD("set_loops", "loops"), &Tween::set_loops, DEFVAL(0));
Expand Down
3 changes: 3 additions & 0 deletions scene/animation/tween.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class Tween : public RefCounted {
int loops = 1;
int loops_done = 0;
float speed_scale = 1;
bool ignore_time_scale = false;

bool is_bound = false;
bool started = false;
Expand Down Expand Up @@ -161,6 +162,8 @@ class Tween : public RefCounted {
TweenProcessMode get_process_mode();
Ref<Tween> set_pause_mode(TweenPauseMode p_mode);
TweenPauseMode get_pause_mode();
Ref<Tween> set_ignore_time_scale(bool p_ignore = true);
bool is_ignoring_time_scale() const;

Ref<Tween> set_parallel(bool p_parallel);
Ref<Tween> set_loops(int p_loops);
Expand Down
3 changes: 2 additions & 1 deletion scene/main/scene_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,8 @@ void SceneTree::process_tweens(double p_delta, bool p_physics) {
continue;
}

if (!E->get()->step(p_delta)) {
double time_step = E->get()->is_ignoring_time_scale() ? Engine::get_singleton()->get_process_step() : p_delta;
if (!E->get()->step(time_step)) {
E->get()->clear();
tweens.erase(E);
}
Expand Down