From 5ef88cf577ad45b4dece733f1bb1350f7c93547e Mon Sep 17 00:00:00 2001 From: robfram Date: Thu, 1 Mar 2018 19:52:00 +0100 Subject: [PATCH] Added `get_playing_speed` method to AnimationPlayer, returning the actual playing speed of the animation being played. As stated in #16550, there is no way to get the playing speed of an animation. The `playback_speed` property is for the whole AnimationPlayer node, and the argument passed to `play` method is another scale applied in top of the AnimationPlayer properties. Thus, the actual playing speed is AnimationPlayer.speed_scale * AnimationPlayer.playback.current.speed_scale. If it is not playing, the method returns 0. --- doc/classes/AnimationPlayer.xml | 8 ++++++++ scene/animation/animation_player.cpp | 8 ++++++++ scene/animation/animation_player.h | 1 + 3 files changed, 17 insertions(+) diff --git a/doc/classes/AnimationPlayer.xml b/doc/classes/AnimationPlayer.xml index 178c714a206..ed859169fd7 100644 --- a/doc/classes/AnimationPlayer.xml +++ b/doc/classes/AnimationPlayer.xml @@ -103,6 +103,14 @@ Get the blend time (in seconds) between two animations, referenced by their names. + + + + + Get the actual playing speed of current animation or 0 if not playing. This speed is the [code]playback_speed[/code] property multiplied by [code]custom_speed[/code] argument specified when calling the [code]play[/code] method. + + + diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 9db4a5fb049..859c40701e2 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -1024,6 +1024,13 @@ float AnimationPlayer::get_speed_scale() const { return speed_scale; } +float AnimationPlayer::get_playing_speed() const { + + if (!playing) { + return 0; + } + return speed_scale * playback.current.speed_scale; +} void AnimationPlayer::seek(float p_time, bool p_update) { @@ -1315,6 +1322,7 @@ void AnimationPlayer::_bind_methods() { ClassDB::bind_method(D_METHOD("set_speed_scale", "speed"), &AnimationPlayer::set_speed_scale); ClassDB::bind_method(D_METHOD("get_speed_scale"), &AnimationPlayer::get_speed_scale); + ClassDB::bind_method(D_METHOD("get_playing_speed"), &AnimationPlayer::get_playing_speed); ClassDB::bind_method(D_METHOD("set_autoplay", "name"), &AnimationPlayer::set_autoplay); ClassDB::bind_method(D_METHOD("get_autoplay"), &AnimationPlayer::get_autoplay); diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index ef758bac44a..af2022ddac7 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -293,6 +293,7 @@ public: void set_speed_scale(float p_speed); float get_speed_scale() const; + float get_playing_speed() const; void set_autoplay(const String &p_name); String get_autoplay() const;