You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
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 specifiedrect
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.The text was updated successfully, but these errors were encountered: