Attention: Here be dragons
This is the
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
A 2D axis-aligned bounding box using integer coordinates.
The Rect2i built-in Variant type represents an axis-aligned rectangle in a 2D space, using integer coordinates. It is defined by its position and size, which are Vector2i. Because it does not rotate, it is frequently used for fast overlap tests (see intersects).
For floating-point coordinates, see Rect2.
There are notable differences when using this API with C#. See C# API 与 GDScript 的差异 for more information.
Rect2i ( )
abs ( ) const
get_area ( ) const
get_center ( ) const
has_area ( ) const
Vector2i end =
The ending point. This is usually the bottom-right corner of the rectangle, and is equivalent to
position + size. Setting this point affects the size.
Vector2i position =
The origin point. This is usually the top-left corner of the rectangle.
Vector2i size =
Note: It's recommended setting the width and height to non-negative values, as most methods in Godot assume that the position is the top-left corner, and the end is the bottom-right corner. To get an equivalent rectangle with non-negative size, use abs.
Rect2i Rect2i ( )
Constructs a Rect2i as a copy of the given Rect2i.
Constructs a Rect2i from a Rect2. The floating-point coordinates are truncated.
Constructs a Rect2i by
Rect2i abs ( ) const
Returns a Rect2i equivalent to this rectangle, with its width and height modified to be non-negative values, and with its position being the top-left corner of the rectangle.
var rect = Rect2i(25, 25, -100, -50) var absolute = rect.abs() # absolute is Rect2i(-75, -25, 100, 50)
var rect = new Rect2I(25, 25, -100, -50); var absolute = rect.Abs(); // absolute is Rect2I(-75, -25, 100, 50)
true if this Rect2i completely encloses another one.
Returns a copy of this rectangle expanded to align the edges with the given
to point, if necessary.
var rect = Rect2i(0, 0, 5, 2) rect = rect.expand(Vector2i(10, 0)) # rect is Rect2i(0, 0, 10, 2) rect = rect.expand(Vector2i(-5, 5)) # rect is Rect2i(-5, 0, 10, 5)
var rect = new Rect2I(0, 0, 5, 2); rect = rect.Expand(new Vector2I(10, 0)); // rect is Rect2I(0, 0, 10, 2) rect = rect.Expand(new Vector2I(-5, 5));