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

Implement AnimationPlayer pause() and resume() #44345

Closed
Closed
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
61 changes: 27 additions & 34 deletions doc/classes/AnimationPlayer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<return type="float">
</return>
<description>
Gets the actual playing speed of current animation or 0 if not playing. This speed is the [member playback_speed] property multiplied by [code]custom_speed[/code] argument specified when calling the [method play] method.
Gets the actual playing speed of current animation or 0 if not playing. This speed is the [member playback_speed] property multiplied by [code]custom_speed[/code] argument specified when calling the [method start] method.
</description>
</method>
<method name="get_queue">
Expand All @@ -131,36 +131,14 @@
<return type="bool">
</return>
<description>
Returns [code]true[/code] if playing an animation.
Returns [code]true[/code] if an animation is playing. An animation is playing if it has started, but not finished or been paused.
</description>
</method>
<method name="play">
<method name="pause">
<return type="void">
</return>
<argument index="0" name="name" type="StringName" default="&quot;&quot;">
</argument>
<argument index="1" name="custom_blend" type="float" default="-1">
</argument>
<argument index="2" name="custom_speed" type="float" default="1.0">
</argument>
<argument index="3" name="from_end" type="bool" default="false">
</argument>
<description>
Plays the animation with key [code]name[/code]. Custom blend times and speed can be set. If [code]custom_speed[/code] is negative and [code]from_end[/code] is [code]true[/code], the animation will play backwards (which is equivalent to calling [method play_backwards]).
The [AnimationPlayer] keeps track of its current or last played animation with [member assigned_animation]. If this method is called with that same animation [code]name[/code], or with no [code]name[/code] parameter, the assigned animation will resume playing if it was paused, or restart if it was stopped (see [method stop] for both pause and stop). If the animation was already playing, it will keep playing.
[b]Note:[/b] The animation will be updated the next time the [AnimationPlayer] is processed. If other variables are updated at the same time this is called, they may be updated too early. To perform the update immediately, call [code]advance(0)[/code].
</description>
</method>
<method name="play_backwards">
<return type="void">
</return>
<argument index="0" name="name" type="StringName" default="&quot;&quot;">
</argument>
<argument index="1" name="custom_blend" type="float" default="-1">
</argument>
<description>
Plays the animation with key [code]name[/code] in reverse.
This method is a shorthand for [method play] with [code]custom_speed = -1.0[/code] and [code]from_end = true[/code], so see its description for more information.
Pauses the currently playing animation. To resume the animation again use [method resume]. To stop and reset an animation use [method stop].
</description>
</method>
<method name="queue">
Expand Down Expand Up @@ -193,6 +171,13 @@
Renames an existing animation with key [code]name[/code] to [code]newname[/code].
</description>
</method>
<method name="resume">
<return type="void">
</return>
<description>
Resumes an animation that was paused. See [method pause].
</description>
</method>
<method name="seek">
<return type="void">
</return>
Expand All @@ -217,14 +202,25 @@
Specifies a blend time (in seconds) between two animations, referenced by their names.
</description>
</method>
<method name="stop">
<method name="start">
<return type="void">
</return>
<argument index="0" name="reset" type="bool" default="true">
<argument index="0" name="name" type="StringName" default="&quot;&quot;">
</argument>
<argument index="1" name="custom_blend_time" type="float" default="-1">
</argument>
<argument index="2" name="custom_speed" type="float" default="1.0">
</argument>
<description>
Stops or pauses the currently playing animation. If [code]reset[/code] is [code]true[/code], the animation position is reset to [code]0[/code] and the playback speed is reset to [code]1.0[/code].
If [code]reset[/code] is [code]false[/code], the [member current_animation_position] will be kept and calling [method play] or [method play_backwards] without arguments or with the same animation name as [member assigned_animation] will resume the animation.
Starts playing the currently assigned animation or the animation with key [code]name[/code] from the beginning. A custom blend time and speed can be set. If [code]custom_speed[/code] is negative, the animation will play backwards from the end.
[b]Note:[/b] The animation will be updated the next time the [AnimationPlayer] is processed. If other variables are updated at the same time this is called, they may be updated too early. To perform the update immediately, call [code]advance(0)[/code].
</description>
</method>
<method name="stop">
<return type="void">
</return>
<description>
Stops and resets the currently playing animation. To keep the animation at its current position, use [method pause].
</description>
</method>
</methods>
Expand All @@ -236,7 +232,7 @@
The name of the animation to play when the scene loads.
</member>
<member name="current_animation" type="String" setter="set_current_animation" getter="get_current_animation" default="&quot;&quot;">
The name of the currently playing animation. If no animation is playing, the property's value is an empty string. Changing this value does not restart the animation. See [method play] for more information on playing animations.
The name of the currently playing animation. If no animation is playing, the property's value is an empty string. Changing this value does not start the animation. See [method start] for more information on starting the animation.
[b]Note[/b]: while this property appears in the inspector, it's not meant to be edited, and it's not saved in the scene. This property is mainly used to get the currently playing animation, and internally for animation playback tracks. For more information, see [Animation].
</member>
<member name="current_animation_length" type="float" setter="" getter="get_current_animation_length">
Expand All @@ -248,9 +244,6 @@
<member name="method_call_mode" type="int" setter="set_method_call_mode" getter="get_method_call_mode" enum="AnimationPlayer.AnimationMethodCallMode" default="0">
The call mode to use for Call Method tracks.
</member>
<member name="playback_active" type="bool" setter="set_active" getter="is_active">
If [code]true[/code], updates animations in response to process-related notifications.
</member>
<member name="playback_default_blend_time" type="float" setter="set_default_blend_time" getter="get_default_blend_time" default="0.0">
The default time in which to blend animations. Ranges from 0 to 4096 with 0.01 precision.
</member>
Expand Down
12 changes: 6 additions & 6 deletions editor/plugins/animation_player_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void AnimationPlayerEditor::_play_pressed() {
if (current == player->get_assigned_animation()) {
player->stop(); //so it won't blend with itself
}
player->play(current);
player->start(current);
}

//unstop
Expand All @@ -212,7 +212,7 @@ void AnimationPlayerEditor::_play_from_pressed() {
player->stop(); //so it won't blend with itself
}

player->play(current);
player->start(current);
player->seek(time);
}

Expand All @@ -230,7 +230,7 @@ void AnimationPlayerEditor::_play_bw_pressed() {
if (current == player->get_assigned_animation()) {
player->stop(); //so it won't blend with itself
}
player->play(current, -1, -1, true);
player->start(current, -1, -1);
}

//unstop
Expand All @@ -249,7 +249,7 @@ void AnimationPlayerEditor::_play_bw_from_pressed() {
player->stop(); //so it won't blend with itself
}

player->play(current, -1, -1, true);
player->start(current, -1, -1);
player->seek(time);
}

Expand All @@ -262,7 +262,7 @@ void AnimationPlayerEditor::_stop_pressed() {
return;
}

player->stop(false);
player->pause();
play->set_pressed(false);
stop->set_pressed(true);
}
Expand Down Expand Up @@ -1020,7 +1020,7 @@ void AnimationPlayerEditor::_seek_value_changed(float p_value, bool p_set) {

player->seek_delta(pos, pos - cpos);
} else {
player->stop(true);
player->stop();
player->seek(pos, true);
}

Expand Down
6 changes: 5 additions & 1 deletion scene/2d/visibility_notifier_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,11 @@ void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) {
AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(p_node);

if (ap) {
ap->set_active(p_enabled);
if (p_enabled) {
ap->resume();
} else {
ap->pause();
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion scene/3d/visibility_notifier_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ void VisibilityEnabler3D::_change_node_state(Node *p_node, bool p_enabled) {
AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(p_node);

if (ap) {
ap->set_active(p_enabled);
if (p_enabled) {
ap->resume();
} else {
ap->pause();
}
}
}
}
Expand Down
Loading