Skip to content

Commit

Permalink
Merge pull request #74454 from Pennycook/get_loops_left
Browse files Browse the repository at this point in the history
Add get_loops_left() function to Tween
  • Loading branch information
YuriSizov authored Mar 25, 2023
2 parents 2be7a9b + 4cb2085 commit 82814f4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/classes/Tween.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@
Returns [code]true[/code] if the [Tween] still has [Tweener]s that haven't finished.
</description>
</method>
<method name="get_loops_left" qualifiers="const">
<return type="int" />
<description>
Returns the number of remaining loops for this [Tween] (see [method set_loops]). A return value of [code]-1[/code] indicates an infinitely looping [Tween], and a return value of [code]0[/code] indicates that the [Tween] has already finished.
</description>
</method>
<method name="get_total_elapsed_time" qualifiers="const">
<return type="float" />
<description>
Expand Down
9 changes: 9 additions & 0 deletions scene/animation/tween.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,14 @@ Ref<Tween> Tween::set_loops(int p_loops) {
return this;
}

int Tween::get_loops_left() const {
if (loops <= 0) {
return -1; // Infinite loop.
} else {
return loops - loops_done;
}
}

Ref<Tween> Tween::set_speed_scale(float p_speed) {
speed_scale = p_speed;
return this;
Expand Down Expand Up @@ -442,6 +450,7 @@ void Tween::_bind_methods() {

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));
ClassDB::bind_method(D_METHOD("get_loops_left"), &Tween::get_loops_left);
ClassDB::bind_method(D_METHOD("set_speed_scale", "speed"), &Tween::set_speed_scale);
ClassDB::bind_method(D_METHOD("set_trans", "trans"), &Tween::set_trans);
ClassDB::bind_method(D_METHOD("set_ease", "ease"), &Tween::set_ease);
Expand Down
1 change: 1 addition & 0 deletions scene/animation/tween.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class Tween : public RefCounted {

Ref<Tween> set_parallel(bool p_parallel);
Ref<Tween> set_loops(int p_loops);
int get_loops_left() const;
Ref<Tween> set_speed_scale(float p_speed);
Ref<Tween> set_trans(TransitionType p_trans);
TransitionType get_trans();
Expand Down

0 comments on commit 82814f4

Please sign in to comment.