summaryrefslogtreecommitdiff
path: root/scene/resources/texture.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-04-29 09:14:37 +0200
committerGitHub <noreply@github.com>2020-04-29 09:14:37 +0200
commitdfe38fbf8a08f9cfff2729a3c4139e60a3cbd194 (patch)
treec891d295297ad4f3afd4d32ce60b5b3c48f2eadb /scene/resources/texture.cpp
parenta17bdb10a938e21901fb65984f38debb01f03f7b (diff)
parentf5029e18ca24e775621be7c3f2e38c47069ecc80 (diff)
Merge pull request #38287 from JiRuifanCR/animatedtexture-oneshot-pause-set-frame
Add set_frame, pause, and oneshot to AnimatedTexture
Diffstat (limited to 'scene/resources/texture.cpp')
-rw-r--r--scene/resources/texture.cpp50
1 files changed, 48 insertions, 2 deletions
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index f431a2ad48..d57af29599 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -1692,15 +1692,20 @@ void AnimatedTexture::_update_proxy() {
}
int iter_max = frame_count;
- while (iter_max) {
+ while (iter_max && !pause) {
float frame_limit = limit + frames[current_frame].delay_sec;
if (time > frame_limit) {
current_frame++;
if (current_frame >= frame_count) {
- current_frame = 0;
+ if (oneshot) {
+ current_frame = frame_count - 1;
+ } else {
+ current_frame = 0;
+ }
}
time -= frame_limit;
+ _change_notify("current_frame");
} else {
break;
}
@@ -1723,6 +1728,33 @@ int AnimatedTexture::get_frames() const {
return frame_count;
}
+void AnimatedTexture::set_current_frame(int p_frame) {
+ ERR_FAIL_COND(p_frame < 0 || p_frame >= frame_count);
+
+ RWLockWrite r(rw_lock);
+
+ current_frame = p_frame;
+}
+int AnimatedTexture::get_current_frame() const {
+ return current_frame;
+}
+
+void AnimatedTexture::set_pause(bool p_pause) {
+ RWLockWrite r(rw_lock);
+ pause = p_pause;
+}
+bool AnimatedTexture::get_pause() const {
+ return pause;
+}
+
+void AnimatedTexture::set_oneshot(bool p_oneshot) {
+ RWLockWrite r(rw_lock);
+ oneshot = p_oneshot;
+}
+bool AnimatedTexture::get_oneshot() const {
+ return oneshot;
+}
+
void AnimatedTexture::set_frame_texture(int p_frame, const Ref<Texture2D> &p_texture) {
ERR_FAIL_COND(p_texture == this);
@@ -1833,6 +1865,15 @@ void AnimatedTexture::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_frames", "frames"), &AnimatedTexture::set_frames);
ClassDB::bind_method(D_METHOD("get_frames"), &AnimatedTexture::get_frames);
+ ClassDB::bind_method(D_METHOD("set_current_frame", "frame"), &AnimatedTexture::set_current_frame);
+ ClassDB::bind_method(D_METHOD("get_current_frame"), &AnimatedTexture::get_current_frame);
+
+ ClassDB::bind_method(D_METHOD("set_pause", "pause"), &AnimatedTexture::set_pause);
+ ClassDB::bind_method(D_METHOD("get_pause"), &AnimatedTexture::get_pause);
+
+ ClassDB::bind_method(D_METHOD("set_oneshot", "oneshot"), &AnimatedTexture::set_oneshot);
+ ClassDB::bind_method(D_METHOD("get_oneshot"), &AnimatedTexture::get_oneshot);
+
ClassDB::bind_method(D_METHOD("set_fps", "fps"), &AnimatedTexture::set_fps);
ClassDB::bind_method(D_METHOD("get_fps"), &AnimatedTexture::get_fps);
@@ -1843,6 +1884,9 @@ void AnimatedTexture::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_frame_delay", "frame"), &AnimatedTexture::get_frame_delay);
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, "", 0), "set_current_frame", "get_current_frame");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pause"), "set_pause", "get_pause");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "oneshot"), "set_oneshot", "get_oneshot");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fps", PROPERTY_HINT_RANGE, "0,1024,0.1"), "set_fps", "get_fps");
for (int i = 0; i < MAX_FRAMES; i++) {
@@ -1864,6 +1908,8 @@ AnimatedTexture::AnimatedTexture() {
fps = 4;
prev_ticks = 0;
current_frame = 0;
+ pause = false;
+ oneshot = false;
RenderingServer::get_singleton()->connect("frame_pre_draw", callable_mp(this, &AnimatedTexture::_update_proxy));
#ifndef NO_THREADS