Skip to content

Commit

Permalink
Rename AnimationPlayer::play() to start()
Browse files Browse the repository at this point in the history
- Removes play_backwards()
- Removes start() from_end parameter. If custom_speed is negative,
  it will automatically play the animation backwards from the end.
  • Loading branch information
madmiraal committed Jul 12, 2022
1 parent ea02f31 commit 46f14a9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 52 deletions.
38 changes: 14 additions & 24 deletions doc/classes/AnimationPlayer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<method name="get_playing_speed" qualifiers="const">
<return type="float" />
<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 Down Expand Up @@ -138,26 +138,6 @@
[b]Note:[/b] Has no effect if the animation is not playing. See [method is_playing]
</description>
</method>
<method name="play">
<return type="void" />
<argument index="0" name="name" type="StringName" default="&quot;&quot;" />
<argument index="1" name="custom_blend" type="float" default="-1" />
<argument index="2" name="custom_speed" type="float" default="1.0" />
<argument index="3" name="from_end" type="bool" default="false" />
<description>
Plays the currently assigned animation or the animation with key [code]name[/code] from the beginning. 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]).
[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" />
<argument index="0" name="name" type="StringName" default="&quot;&quot;" />
<argument index="1" name="custom_blend" type="float" default="-1" />
<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.
</description>
</method>
<method name="queue">
<return type="void" />
<argument index="0" name="name" type="StringName" />
Expand All @@ -183,7 +163,7 @@
<return type="void" />
<description>
Resumes an animation that was paused. See [method pause].
[b]Note:[/b] Has no effect if the animation is not paused. It will not start an animation that was not playing or is finished. See [method play].
[b]Note:[/b] Has no effect if the animation is not paused. It will not start an animation that was not playing or is finished. See [method start].
</description>
</method>
<method name="seek">
Expand All @@ -204,6 +184,16 @@
Specifies a blend time (in seconds) between two animations, referenced by their names.
</description>
</method>
<method name="start">
<return type="void" />
<argument index="0" name="name" type="StringName" default="&quot;&quot;" />
<argument index="1" name="custom_blend_time" type="float" default="-1" />
<argument index="2" name="custom_speed" type="float" default="1.0" />
<description>
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" />
<description>
Expand All @@ -219,7 +209,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 Down Expand Up @@ -254,7 +244,7 @@
<argument index="1" name="new_name" type="StringName" />
<description>
Emitted when a queued animation plays after the previous animation was finished. See [method queue].
[b]Note:[/b] The signal is not emitted when the animation is changed via [method play] or from [AnimationTree].
[b]Note:[/b] The signal is not emitted when the animation is changed via [method start] or from [AnimationTree].
</description>
</signal>
<signal name="animation_finished">
Expand Down
8 changes: 4 additions & 4 deletions editor/plugins/animation_player_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,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 @@ -215,7 +215,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 @@ -236,7 +236,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 @@ -252,7 +252,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 Down
34 changes: 14 additions & 20 deletions scene/animation/animation_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ void AnimationPlayer::_notification(int p_what) {

case NOTIFICATION_READY: {
if (!Engine::get_singleton()->is_editor_hint() && animation_set.has(autoplay)) {
play(autoplay);
start(autoplay);
_animation_process(0);
}
} break;
Expand Down Expand Up @@ -905,7 +905,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, double
}

if (player->is_playing() || p_seeked) {
player->play(anim_name);
player->start(anim_name);
player->seek(at_anim_pos);
nc->animation_playing = true;
playing_caches.insert(nc);
Expand All @@ -928,8 +928,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, double
nc->animation_playing = false;
}
} else {
player->play(anim_name);
player->seek(0.0, true);
player->start(anim_name);
nc->animation_playing = true;
playing_caches.insert(nc);
}
Expand Down Expand Up @@ -1166,7 +1165,7 @@ void AnimationPlayer::_animation_process(double p_delta) {
if (end_reached) {
if (queued.size()) {
String old = playback.assigned;
play(queued.front()->get());
start(queued.front()->get());
String new_name = playback.assigned;
queued.pop_front();
if (end_notify) {
Expand Down Expand Up @@ -1522,7 +1521,7 @@ float AnimationPlayer::get_blend_time(const StringName &p_animation1, const Stri

void AnimationPlayer::queue(const StringName &p_name) {
if (!is_playing()) {
play(p_name);
start(p_name);
} else {
queued.push_back(p_name);
}
Expand All @@ -1541,11 +1540,7 @@ void AnimationPlayer::clear_queue() {
queued.clear();
}

void AnimationPlayer::play_backwards(const StringName &p_name, float p_custom_blend) {
play(p_name, p_custom_blend, -1, true);
}

void AnimationPlayer::play(const StringName &p_name, float p_custom_blend, float p_custom_scale, bool p_from_end) {
void AnimationPlayer::start(const StringName &p_name, float p_custom_blend_time, float p_custom_scale) {
StringName name = p_name;

if (String(name) == "") {
Expand All @@ -1563,8 +1558,8 @@ void AnimationPlayer::play(const StringName &p_name, float p_custom_blend, float
bk.from = c.current.from->name;
bk.to = name;

if (p_custom_blend >= 0) {
blend_time = p_custom_blend;
if (p_custom_blend_time >= 0) {
blend_time = p_custom_blend_time;
} else if (blend_times.has(bk)) {
blend_time = blend_times[bk];
} else {
Expand All @@ -1581,7 +1576,7 @@ void AnimationPlayer::play(const StringName &p_name, float p_custom_blend, float
}
}

if (p_custom_blend < 0 && blend_time == 0 && default_blend_time) {
if (p_custom_blend_time < 0 && blend_time == 0 && default_blend_time) {
blend_time = default_blend_time;
}
if (blend_time > 0) {
Expand All @@ -1595,7 +1590,7 @@ void AnimationPlayer::play(const StringName &p_name, float p_custom_blend, float
_stop_playing_caches();

c.current.from = &animation_set[name];
c.current.pos = p_from_end ? c.current.from->animation->get_length() : 0;
c.current.pos = p_custom_scale < 0 ? c.current.from->animation->get_length() : 0;
c.current.speed_scale = p_custom_scale;
c.assigned = name;
c.seeked = false;
Expand Down Expand Up @@ -1628,7 +1623,7 @@ void AnimationPlayer::set_current_animation(const String &p_anim) {
if (p_anim == "[stop]" || p_anim.is_empty()) {
stop();
} else if (!is_playing() || playback.assigned != p_anim) {
play(p_anim);
start(p_anim);
} else {
// Same animation, do not replay from start
}
Expand All @@ -1640,7 +1635,7 @@ String AnimationPlayer::get_current_animation() const {

void AnimationPlayer::set_assigned_animation(const String &p_anim) {
if (is_playing()) {
play(p_anim);
start(p_anim);
} else {
ERR_FAIL_COND_MSG(!animation_set.has(p_anim), vformat("Animation not found: %s.", p_anim));
playback.current.pos = 0;
Expand Down Expand Up @@ -1937,7 +1932,7 @@ NodePath AnimationPlayer::get_root() const {

void AnimationPlayer::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
String pf = p_function;
if (p_idx == 0 && (p_function == "play" || p_function == "play_backwards" || p_function == "has_animation" || p_function == "queue")) {
if (p_idx == 0 && (p_function == "start" || p_function == "has_animation" || p_function == "queue")) {
List<StringName> al;
get_animation_list(&al);
for (const StringName &name : al) {
Expand Down Expand Up @@ -2067,8 +2062,7 @@ void AnimationPlayer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_default_blend_time", "sec"), &AnimationPlayer::set_default_blend_time);
ClassDB::bind_method(D_METHOD("get_default_blend_time"), &AnimationPlayer::get_default_blend_time);

ClassDB::bind_method(D_METHOD("play", "name", "custom_blend", "custom_speed", "from_end"), &AnimationPlayer::play, DEFVAL(""), DEFVAL(-1), DEFVAL(1.0), DEFVAL(false));
ClassDB::bind_method(D_METHOD("play_backwards", "name", "custom_blend"), &AnimationPlayer::play_backwards, DEFVAL(""), DEFVAL(-1));
ClassDB::bind_method(D_METHOD("start", "name", "custom_blend_time", "custom_speed"), &AnimationPlayer::start, DEFVAL(""), DEFVAL(-1), DEFVAL(1.0));
ClassDB::bind_method(D_METHOD("pause"), &AnimationPlayer::pause);
ClassDB::bind_method(D_METHOD("resume"), &AnimationPlayer::resume);
ClassDB::bind_method(D_METHOD("stop"), &AnimationPlayer::stop);
Expand Down
3 changes: 1 addition & 2 deletions scene/animation/animation_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,7 @@ class AnimationPlayer : public Node {
void set_default_blend_time(float p_default);
float get_default_blend_time() const;

void play(const StringName &p_name = StringName(), float p_custom_blend = -1, float p_custom_scale = 1.0, bool p_from_end = false);
void play_backwards(const StringName &p_name = StringName(), float p_custom_blend = -1);
void start(const StringName &p_name = StringName(), float p_custom_blend_time = -1, float p_custom_scale = 1.0);
void queue(const StringName &p_name);
Vector<String> get_queue();
void clear_queue();
Expand Down
4 changes: 2 additions & 2 deletions scene/animation/animation_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,7 @@ void AnimationTree::_process_graph(double p_delta) {
}

if (player2->is_playing() || seeked) {
player2->play(anim_name);
player2->start(anim_name);
player2->seek(at_anim_pos);
t->playing = true;
playing_caches.insert(t);
Expand All @@ -1576,7 +1576,7 @@ void AnimationTree::_process_graph(double p_delta) {
t->playing = false;
}
} else {
player2->play(anim_name);
player2->start(anim_name);
t->playing = true;
playing_caches.insert(t);
}
Expand Down

0 comments on commit 46f14a9

Please sign in to comment.