Fix rendering centered odd-size texture in AnimatedSprite2D/AnimatedSprite3D

This commit is contained in:
kleonc 2021-09-25 12:18:18 +02:00
parent a88e82078d
commit b266b59e56
2 changed files with 8 additions and 11 deletions

View File

@ -94,7 +94,7 @@ Rect2 AnimatedSprite2D::_get_rect() const {
Point2 ofs = offset; Point2 ofs = offset;
if (centered) { if (centered) {
ofs -= Size2(s) / 2; ofs -= s / 2;
} }
if (s == Size2(0, 0)) { if (s == Size2(0, 0)) {
@ -228,8 +228,7 @@ void AnimatedSprite2D::_notification(int p_what) {
RID ci = get_canvas_item(); RID ci = get_canvas_item();
Size2i s; Size2 s = texture->get_size();
s = texture->get_size();
Point2 ofs = offset; Point2 ofs = offset;
if (centered) { if (centered) {
ofs -= s / 2; ofs -= s / 2;

View File

@ -712,7 +712,7 @@ Rect2 Sprite3D::get_item_rect() const {
return CanvasItem::get_item_rect(); return CanvasItem::get_item_rect();
*/ */
Size2i s; Size2 s;
if (region) { if (region) {
s = region_rect.size; s = region_rect.size;
@ -807,22 +807,20 @@ void AnimatedSprite3D::_draw() {
set_base(RID()); set_base(RID());
return; //no texuture no life return; //no texuture no life
} }
Vector2 tsize = texture->get_size(); Size2 tsize = texture->get_size();
if (tsize.x == 0 || tsize.y == 0) { if (tsize.x == 0 || tsize.y == 0) {
return; return;
} }
Size2i s = tsize;
Rect2 src_rect; Rect2 src_rect;
src_rect.size = tsize;
src_rect.size = s;
Point2 ofs = get_offset(); Point2 ofs = get_offset();
if (is_centered()) { if (is_centered()) {
ofs -= s / 2; ofs -= tsize / 2;
} }
Rect2 dst_rect(ofs, s); Rect2 dst_rect(ofs, tsize);
Rect2 final_rect; Rect2 final_rect;
Rect2 final_src_rect; Rect2 final_src_rect;
@ -1133,7 +1131,7 @@ Rect2 AnimatedSprite3D::get_item_rect() const {
if (t.is_null()) { if (t.is_null()) {
return Rect2(0, 0, 1, 1); return Rect2(0, 0, 1, 1);
} }
Size2i s = t->get_size(); Size2 s = t->get_size();
Point2 ofs = get_offset(); Point2 ofs = get_offset();
if (centered) { if (centered) {