summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
authorSilc Renew <tokage.it.lab@gmail.com>2023-01-21 14:51:03 +0900
committerSilc Renew <tokage.it.lab@gmail.com>2023-01-26 12:40:19 +0900
commit17bf6238fc3dca1b2ec6c1a0bbe11d5e7d7a8113 (patch)
tree3b4bb69db09279c346c203687954b3296a9570e6 /scene/resources
parent35c37ce4ce5d1559ae4548ebb2c0c7286cb90a3d (diff)
Make AnimatedSprite's playback API consistent with AnimationPlayer
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/sprite_frames.cpp6
-rw-r--r--scene/resources/sprite_frames.h8
2 files changed, 8 insertions, 6 deletions
diff --git a/scene/resources/sprite_frames.cpp b/scene/resources/sprite_frames.cpp
index c101974248..818be38681 100644
--- a/scene/resources/sprite_frames.cpp
+++ b/scene/resources/sprite_frames.cpp
@@ -36,7 +36,7 @@ void SpriteFrames::add_frame(const StringName &p_anim, const Ref<Texture2D> &p_t
HashMap<StringName, Anim>::Iterator E = animations.find(p_anim);
ERR_FAIL_COND_MSG(!E, "Animation '" + String(p_anim) + "' doesn't exist.");
- p_duration = MAX(0.0, p_duration);
+ p_duration = MAX(SPRITE_FRAME_MINIMUM_DURATION, p_duration);
Frame frame = { p_texture, p_duration };
@@ -57,7 +57,7 @@ void SpriteFrames::set_frame(const StringName &p_anim, int p_idx, const Ref<Text
return;
}
- p_duration = MAX(0.0, p_duration);
+ p_duration = MAX(SPRITE_FRAME_MINIMUM_DURATION, p_duration);
Frame frame = { p_texture, p_duration };
@@ -214,7 +214,7 @@ void SpriteFrames::_set_animations(const Array &p_animations) {
ERR_CONTINUE(!f.has("texture"));
ERR_CONTINUE(!f.has("duration"));
- Frame frame = { f["texture"], f["duration"] };
+ Frame frame = { f["texture"], MAX(SPRITE_FRAME_MINIMUM_DURATION, (float)f["duration"]) };
anim.frames.push_back(frame);
}
diff --git a/scene/resources/sprite_frames.h b/scene/resources/sprite_frames.h
index 61bead6948..6de2b4a37b 100644
--- a/scene/resources/sprite_frames.h
+++ b/scene/resources/sprite_frames.h
@@ -33,6 +33,8 @@
#include "scene/resources/texture.h"
+static const float SPRITE_FRAME_MINIMUM_DURATION = 0.01;
+
class SpriteFrames : public Resource {
GDCLASS(SpriteFrames, Resource);
@@ -89,10 +91,10 @@ public:
_FORCE_INLINE_ float get_frame_duration(const StringName &p_anim, int p_idx) const {
HashMap<StringName, Anim>::ConstIterator E = animations.find(p_anim);
- ERR_FAIL_COND_V_MSG(!E, 0.0, "Animation '" + String(p_anim) + "' doesn't exist.");
- ERR_FAIL_COND_V(p_idx < 0, 0.0);
+ ERR_FAIL_COND_V_MSG(!E, 1.0, "Animation '" + String(p_anim) + "' doesn't exist.");
+ ERR_FAIL_COND_V(p_idx < 0, 1.0);
if (p_idx >= E->value.frames.size()) {
- return 0.0;
+ return 1.0;
}
return E->value.frames[p_idx].duration;