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.

注釈

There are notable differences when using this API with C#. See C# API differences to 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 )