summaryrefslogtreecommitdiffstats
path: root/scene/2d/sprite_2d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d/sprite_2d.cpp')
-rw-r--r--scene/2d/sprite_2d.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/scene/2d/sprite_2d.cpp b/scene/2d/sprite_2d.cpp
index 7e6b43559c..6d0a2968d7 100644
--- a/scene/2d/sprite_2d.cpp
+++ b/scene/2d/sprite_2d.cpp
@@ -261,6 +261,9 @@ Vector2i Sprite2D::get_frame_coords() const {
void Sprite2D::set_vframes(int p_amount) {
ERR_FAIL_COND_MSG(p_amount < 1, "Amount of vframes cannot be smaller than 1.");
vframes = p_amount;
+ if (frame >= vframes * hframes) {
+ frame = 0;
+ }
queue_redraw();
item_rect_changed();
notify_property_list_changed();
@@ -272,7 +275,21 @@ int Sprite2D::get_vframes() const {
void Sprite2D::set_hframes(int p_amount) {
ERR_FAIL_COND_MSG(p_amount < 1, "Amount of hframes cannot be smaller than 1.");
+ if (vframes > 1) {
+ // Adjust the frame to fit new sheet dimensions.
+ int original_column = frame % hframes;
+ if (original_column >= p_amount) {
+ // Frame's column was dropped, reset.
+ frame = 0;
+ } else {
+ int original_row = frame / hframes;
+ frame = original_row * p_amount + original_column;
+ }
+ }
hframes = p_amount;
+ if (frame >= vframes * hframes) {
+ frame = 0;
+ }
queue_redraw();
item_rect_changed();
notify_property_list_changed();