Attention: Here be dragons

This is the `latest` (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

Rect2¶

A 2D axis-aligned bounding box using floating-point coordinates.

Description¶

The Rect2 built-in Variant type represents an axis-aligned rectangle in a 2D space. It is defined by its position and size, which are Vector2. It is frequently used for fast overlap tests (see intersects). Although Rect2 itself is axis-aligned, it can be combined with Transform2D to represent a rotated or skewed rectangle.

For integer coordinates, use Rect2i. The 3D equivalent to Rect2 is AABB.

Note: Negative values for size are not supported. With negative size, most Rect2 methods do not work correctly. Use abs to get an equivalent Rect2 with a non-negative size.

Note: In a boolean context, a Rect2 evaluates to `false` if both position and size are zero (equal to Vector2.ZERO). Otherwise, it always evaluates to `true`.

Nota

There are notable differences when using this API with C#. See C# API differences to GDScript for more information.

Properties¶

 Vector2 end `Vector2(0, 0)` Vector2 position `Vector2(0, 0)` Vector2 size `Vector2(0, 0)`

Constructors¶

 Rect2 Rect2 ( ) Rect2 Rect2 ( Rect2 from ) Rect2 Rect2 ( Rect2i from ) Rect2 Rect2 ( Vector2 position, Vector2 size ) Rect2 Rect2 ( float x, float y, float width, float height )

Methods¶

 Rect2 abs ( ) const bool encloses ( Rect2 b ) const Rect2 expand ( Vector2 to ) const float get_area ( ) const Vector2 get_center ( ) const Rect2 grow ( float amount ) const Rect2 grow_individual ( float left, float top, float right, float bottom ) const Rect2 grow_side ( int side, float amount ) const bool has_area ( ) const bool has_point ( Vector2 point ) const Rect2 intersection ( Rect2 b ) const bool intersects ( Rect2 b, bool include_borders=false ) const bool is_equal_approx ( Rect2 rect ) const bool is_finite ( ) const Rect2