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.

Rect2i

A 2D axis-aligned bounding box using integer coordinates.

Description

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.

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

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

Note

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

Tutorials

Properties

Vector2i

end

Vector2i(0, 0)

Vector2i

position

Vector2i(0, 0)

Vector2i

size

Vector2i(0, 0)

Constructors

Rect2i

Rect2i()

Rect2i

Rect2i(from: Rect2i)

Rect2i

Rect2i(from: Rect2)

Rect2i

Rect2i(position: Vector2i, size: Vector2i)

Rect2i

Rect2i(x: int, y: int, width: int, height: int)

Methods

Rect2i

abs() const

bool

encloses(b: Rect2i) const

Rect2i

expand(to: Vector2i) const

int

get_area() const

Vector2i

get_center() const

Rect2i

grow(amount: int) const

Rect2i

grow_individual(left: int, top: int, right: int, bottom: int) const

Rect2i

grow_side(side: int, amount: int) const

bool

has_area() const

bool

has_point(point: Vector2i) const

Rect2i

intersection(b: Rect2i) const

bool

intersects(b: Rect2i) const

Rect2i

merge(b: Rect2i) const

Operators

bool

operator !=(right: Rect2i)

bool

operator ==(right: Rect2i)


Property Descriptions

Vector2i end = Vector2i(0, 0)

The end