Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

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.

Примечание

There are notable differences when using this API with C#. See API различия C# и GDScript for more information.

Tutorials

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 )