Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Fix rendering centered odd-size texture in AnimatedSprite/AnimatedSprite3D #53052

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions scene/2d/animated_sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Rect2 AnimatedSprite::_get_rect() const {

Point2 ofs = offset;
if (centered) {
ofs -= Size2(s) / 2;
ofs -= s / 2;
}

if (s == Size2(0, 0)) {
Expand Down Expand Up @@ -436,8 +436,7 @@ void AnimatedSprite::_notification(int p_what) {

RID ci = get_canvas_item();

Size2i s;
s = texture->get_size();
Size2 s = texture->get_size();
Point2 ofs = offset;
if (centered) {
ofs -= s / 2;
Expand Down
14 changes: 6 additions & 8 deletions scene/3d/sprite_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ Rect2 Sprite3D::get_item_rect() const {
return CanvasItem::get_item_rect();
*/

Size2i s;
Size2 s;

if (region) {
s = region_rect.size;
Expand Down Expand Up @@ -782,22 +782,20 @@ void AnimatedSprite3D::_draw() {
set_base(RID());
return; //no texuture no life
}
Vector2 tsize = texture->get_size();
Size2 tsize = texture->get_size();
if (tsize.x == 0 || tsize.y == 0) {
return;
}

Size2i s = tsize;
Rect2 src_rect;

src_rect.size = s;
src_rect.size = tsize;

Point2 ofs = get_offset();
if (is_centered()) {
ofs -= s / 2;
ofs -= tsize / 2;
}
lawnjelly marked this conversation as resolved.
Show resolved Hide resolved

Rect2 dst_rect(ofs, s);
Rect2 dst_rect(ofs, tsize);

Rect2 final_rect;
Rect2 final_src_rect;
Expand Down Expand Up @@ -1085,7 +1083,7 @@ Rect2 AnimatedSprite3D::get_item_rect() const {
if (t.is_null()) {
return Rect2(0, 0, 1, 1);
}
Size2i s = t->get_size();
Size2 s = t->get_size();

Point2 ofs = get_offset();
if (centered) {
Expand Down