summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-06-26 14:51:22 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-06-26 14:51:22 +0200
commitcafe7042b1fa4dc4caab77a99165adf07f88c0f5 (patch)
tree909bfcdd1ff7dab71b74c20e954898fb97c34abf
parent36a5960ab2854f5923a6c36fc66cb9e726ee3f34 (diff)
parentdc6e664fda18ccc7a4a54f16ca64ef4049c9e47e (diff)
downloadredot-engine-cafe7042b1fa4dc4caab77a99165adf07f88c0f5.tar.gz
Merge pull request #93548 from Robocraft999/patch-1
Fix `AnimatedSprite2D/3D::play` using wrong end_frame
-rw-r--r--scene/2d/animated_sprite_2d.cpp5
-rw-r--r--scene/3d/sprite_3d.cpp5
2 files changed, 8 insertions, 2 deletions
diff --git a/scene/2d/animated_sprite_2d.cpp b/scene/2d/animated_sprite_2d.cpp
index 6d380aed3c..3506a0df2b 100644
--- a/scene/2d/animated_sprite_2d.cpp
+++ b/scene/2d/animated_sprite_2d.cpp
@@ -473,9 +473,10 @@ void AnimatedSprite2D::play(const StringName &p_name, float p_custom_scale, bool
playing = true;
custom_speed_scale = p_custom_scale;
- int end_frame = MAX(0, frames->get_frame_count(animation) - 1);
if (name != animation) {
animation = name;
+ int end_frame = MAX(0, frames->get_frame_count(animation) - 1);
+
if (p_from_end) {
set_frame_and_progress(end_frame, 1.0);
} else {
@@ -483,7 +484,9 @@ void AnimatedSprite2D::play(const StringName &p_name, float p_custom_scale, bool
}
emit_signal(SceneStringName(animation_changed));
} else {
+ int end_frame = MAX(0, frames->get_frame_count(animation) - 1);
bool is_backward = signbit(speed_scale * custom_speed_scale);
+
if (p_from_end && is_backward && frame == 0 && frame_progress <= 0.0) {
set_frame_and_progress(end_frame, 1.0);
} else if (!p_from_end && !is_backward && frame == end_frame && frame_progress >= 1.0) {
diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp
index ba3b32a031..d08aeb1de2 100644
--- a/scene/3d/sprite_3d.cpp
+++ b/scene/3d/sprite_3d.cpp
@@ -1334,9 +1334,10 @@ void AnimatedSprite3D::play(const StringName &p_name, float p_custom_scale, bool
playing = true;
custom_speed_scale = p_custom_scale;
- int end_frame = MAX(0, frames->get_frame_count(animation) - 1);
if (name != animation) {
animation = name;
+ int end_frame = MAX(0, frames->get_frame_count(animation) - 1);
+
if (p_from_end) {
set_frame_and_progress(end_frame, 1.0);
} else {
@@ -1344,7 +1345,9 @@ void AnimatedSprite3D::play(const StringName &p_name, float p_custom_scale, bool
}
emit_signal(SceneStringName(animation_changed));
} else {
+ int end_frame = MAX(0, frames->get_frame_count(animation) - 1);
bool is_backward = signbit(speed_scale * custom_speed_scale);
+
if (p_from_end && is_backward && frame == 0 && frame_progress <= 0.0) {
set_frame_and_progress(end_frame, 1.0);
} else if (!p_from_end && !is_backward && frame == end_frame && frame_progress >= 1.0) {