Fix invalid frame index when Sprite2D's hframes or vframes has been changed
This commit is contained in:
parent
066e7d483a
commit
484c5b5aff
4 changed files with 42 additions and 8 deletions
|
|
@ -804,8 +804,11 @@ Vector2i Sprite3D::get_frame_coords() const {
|
|||
}
|
||||
|
||||
void Sprite3D::set_vframes(int p_amount) {
|
||||
ERR_FAIL_COND(p_amount < 1);
|
||||
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();
|
||||
notify_property_list_changed();
|
||||
}
|
||||
|
|
@ -815,8 +818,22 @@ int Sprite3D::get_vframes() const {
|
|||
}
|
||||
|
||||
void Sprite3D::set_hframes(int p_amount) {
|
||||
ERR_FAIL_COND(p_amount < 1);
|
||||
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();
|
||||
notify_property_list_changed();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue