|
@@ -2617,26 +2617,30 @@ void AnimatedTexture::_update_proxy() {
|
|
|
|
|
|
time += delta;
|
|
|
|
|
|
- float limit;
|
|
|
-
|
|
|
- if (fps == 0) {
|
|
|
- limit = 0;
|
|
|
- } else {
|
|
|
- limit = 1.0 / fps;
|
|
|
- }
|
|
|
+ float speed = speed_scale == 0 ? 0 : abs(1.0 / speed_scale);
|
|
|
|
|
|
int iter_max = frame_count;
|
|
|
while (iter_max && !pause) {
|
|
|
- float frame_limit = limit + frames[current_frame].delay_sec;
|
|
|
+ float frame_limit = frames[current_frame].duration * speed;
|
|
|
|
|
|
if (time > frame_limit) {
|
|
|
- current_frame++;
|
|
|
+ if (speed_scale > 0.0) {
|
|
|
+ current_frame++;
|
|
|
+ } else {
|
|
|
+ current_frame--;
|
|
|
+ }
|
|
|
if (current_frame >= frame_count) {
|
|
|
if (one_shot) {
|
|
|
current_frame = frame_count - 1;
|
|
|
} else {
|
|
|
current_frame = 0;
|
|
|
}
|
|
|
+ } else if (current_frame < 0) {
|
|
|
+ if (one_shot) {
|
|
|
+ current_frame = 0;
|
|
|
+ } else {
|
|
|
+ current_frame = frame_count - 1;
|
|
|
+ }
|
|
|
}
|
|
|
time -= frame_limit;
|
|
|
|
|
@@ -2710,30 +2714,30 @@ Ref<Texture2D> AnimatedTexture::get_frame_texture(int p_frame) const {
|
|
|
return frames[p_frame].texture;
|
|
|
}
|
|
|
|
|
|
-void AnimatedTexture::set_frame_delay(int p_frame, float p_delay_sec) {
|
|
|
+void AnimatedTexture::set_frame_duration(int p_frame, float p_duration) {
|
|
|
ERR_FAIL_INDEX(p_frame, MAX_FRAMES);
|
|
|
|
|
|
RWLockRead r(rw_lock);
|
|
|
|
|
|
- frames[p_frame].delay_sec = p_delay_sec;
|
|
|
+ frames[p_frame].duration = p_duration;
|
|
|
}
|
|
|
|
|
|
-float AnimatedTexture::get_frame_delay(int p_frame) const {
|
|
|
+float AnimatedTexture::get_frame_duration(int p_frame) const {
|
|
|
ERR_FAIL_INDEX_V(p_frame, MAX_FRAMES, 0);
|
|
|
|
|
|
RWLockRead r(rw_lock);
|
|
|
|
|
|
- return frames[p_frame].delay_sec;
|
|
|
+ return frames[p_frame].duration;
|
|
|
}
|
|
|
|
|
|
-void AnimatedTexture::set_fps(float p_fps) {
|
|
|
- ERR_FAIL_COND(p_fps < 0 || p_fps >= 1000);
|
|
|
+void AnimatedTexture::set_speed_scale(float p_scale) {
|
|
|
+ ERR_FAIL_COND(p_scale < -1000 || p_scale >= 1000);
|
|
|
|
|
|
- fps = p_fps;
|
|
|
+ speed_scale = p_scale;
|
|
|
}
|
|
|
|
|
|
-float AnimatedTexture::get_fps() const {
|
|
|
- return fps;
|
|
|
+float AnimatedTexture::get_speed_scale() const {
|
|
|
+ return speed_scale;
|
|
|
}
|
|
|
|
|
|
int AnimatedTexture::get_width() const {
|
|
@@ -2812,24 +2816,24 @@ void AnimatedTexture::_bind_methods() {
|
|
|
ClassDB::bind_method(D_METHOD("set_one_shot", "one_shot"), &AnimatedTexture::set_one_shot);
|
|
|
ClassDB::bind_method(D_METHOD("get_one_shot"), &AnimatedTexture::get_one_shot);
|
|
|
|
|
|
- ClassDB::bind_method(D_METHOD("set_fps", "fps"), &AnimatedTexture::set_fps);
|
|
|
- ClassDB::bind_method(D_METHOD("get_fps"), &AnimatedTexture::get_fps);
|
|
|
+ ClassDB::bind_method(D_METHOD("set_speed_scale", "scale"), &AnimatedTexture::set_speed_scale);
|
|
|
+ ClassDB::bind_method(D_METHOD("get_speed_scale"), &AnimatedTexture::get_speed_scale);
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_frame_texture", "frame", "texture"), &AnimatedTexture::set_frame_texture);
|
|
|
ClassDB::bind_method(D_METHOD("get_frame_texture", "frame"), &AnimatedTexture::get_frame_texture);
|
|
|
|
|
|
- ClassDB::bind_method(D_METHOD("set_frame_delay", "frame", "delay"), &AnimatedTexture::set_frame_delay);
|
|
|
- ClassDB::bind_method(D_METHOD("get_frame_delay", "frame"), &AnimatedTexture::get_frame_delay);
|
|
|
+ ClassDB::bind_method(D_METHOD("set_frame_duration", "frame", "duration"), &AnimatedTexture::set_frame_duration);
|
|
|
+ ClassDB::bind_method(D_METHOD("get_frame_duration", "frame"), &AnimatedTexture::get_frame_duration);
|
|
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "frames", PROPERTY_HINT_RANGE, "1," + itos(MAX_FRAMES), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_frames", "get_frames");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_frame", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_current_frame", "get_current_frame");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pause"), "set_pause", "get_pause");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_shot"), "set_one_shot", "get_one_shot");
|
|
|
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fps", PROPERTY_HINT_RANGE, "0,1024,0.1"), "set_fps", "get_fps");
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed_scale", PROPERTY_HINT_RANGE, "-60,60,0.1,or_greater,or_lesser"), "set_speed_scale", "get_speed_scale");
|
|
|
|
|
|
for (int i = 0; i < MAX_FRAMES; i++) {
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "frame_" + itos(i) + "/texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_frame_texture", "get_frame_texture", i);
|
|
|
- ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "frame_" + itos(i) + "/delay_sec", PROPERTY_HINT_RANGE, "0.0,16.0,0.01,suffix:s", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_frame_delay", "get_frame_delay", i);
|
|
|
+ ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "frame_" + itos(i) + "/duration", PROPERTY_HINT_RANGE, "0.0,16.0,0.01,or_greater,suffix:s", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_frame_duration", "get_frame_duration", i);
|
|
|
}
|
|
|
|
|
|
BIND_CONSTANT(MAX_FRAMES);
|