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

Inconsistent behavior in get_rect() between nodes. #38444

Open
CavemanIke opened this issue May 4, 2020 · 1 comment
Open

Inconsistent behavior in get_rect() between nodes. #38444

CavemanIke opened this issue May 4, 2020 · 1 comment

Comments

@CavemanIke
Copy link

Godot version:
3.2.1 stable

Issue description:
The get_rect() method available on a few different types, including Control, Sprite, and Image, do not behave the same.

  • Control.get_rect(): Returns the global position and size of the object.
  • Sprite.get_rect(): Returns the local position of the upper right corner relative to its pivot (if a sprite is 64x64 and the pivot is centered, the upper left origin is -32,-32 regardless of its position on the canvas). This does not change if the sprite is resized on any axis resulting in weird coordinates being returned like -13.2566666667,25.7 if local mouse position is polled.
  • Image.get_rect(Rect2 rect): Returns a copy of the image from the specified rect argument.

I feel this is an inconsistency in the language API that should be smoothed out to avoid confusion with expected behavior by appropriately renaming methods and/or making them behave the same everywhere they are implemented.

An expected and sensible behavior is that get_rect() on all types would simply return the global coordinates of the object from its upper left corner and its bounding box size. This not only simplifies this but will also simplify getting/calculating the mouse position within the objects.

@groud
Copy link
Member

groud commented May 4, 2020

Control.get_rect(): Returns the global position and size of the object.

According to the documentation, this is false. It returns the rect according to the top-left corner of the parent. So it's basically Rect2(position, size) and not Rect2(global_position, size). But well, I agree it is still inconsistent with the Sprite version.

But I believe this inconsistency between the Sprite and Control is understandable. Their positioning system is not exactly the same as the order of transforms is different. Node2Ds have their pivot set first, and then their position is derived from the pivot, while for controls, the position (and thus margins) is computed first, then the pivot is eventually used for the other transforms (scale an rotation). So basically, the pivot matters for Nodes2Ds' position but not that much for Control.

For Image part, I don't think this is really confusing. Image is a resource, it's completely different from something that could be placed in the world. There is not a way to make it consistent with the others as they are not the same thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants