Rect¶
C++ type: Rect
Description¶
An axis-aligned rectangle defined by an origin (x, y) and size (width, height). Used throughout the engine for screen regions, texture atlas frames, viewport definitions, and UI layouts.
Lua components are writable
Lua can read and assign x, y, width, and height directly. Engine properties
such as sprite.textureRect return rect values, so assign a mutated value back to
persist it: local r = sprite.textureRect; r.width = 64; sprite.textureRect = r.
Properties¶
| Type | Name | Default | Langs |
|---|---|---|---|
| float | x | 0.0 |
C++ | Lua |
| float | y | 0.0 |
C++ | Lua |
| float | width | 0.0 |
C++ | Lua |
| float | height | 0.0 |
C++ | Lua |
Methods¶
| Type | Name | Langs |
|---|---|---|
| void | setRect | C++ | Lua |
| Vector4 | getVector | C++ | Lua |
| Rect& | fitOnRect | C++ | Lua |
| bool | contains | C++ | Lua |
| bool | isNormalized | C++ | Lua |
| bool | isZero | C++ | Lua |
| std::string | toString | C++ | Lua |
Property details¶
x / y / width / height¶
- Getter/Setter: float getX() / void setX(float x)
- Getter/Setter: float getY() / void setY(float y)
- Getter/Setter: float getWidth() / void setWidth(float width)
- Getter/Setter: float getHeight() / void setHeight(float height)
The four components of the rectangle.
Method details¶
setRect¶
- void setRect(float x, float y, float width, float height)
- void setRect(Rect rect)
Sets all four components at once.
getVector¶
- Vector4 getVector()
Returns the rect as a Vector4(x, y, width, height).
fitOnRect¶
- Rect& fitOnRect(Rect rect)
Scales and positions this rect to fit inside rect while preserving the aspect ratio. Modifies in-place and returns *this.
contains¶
- bool contains(Vector2 point)
Returns true if point lies inside this rectangle (inclusive).
isNormalized¶
- bool isNormalized() const
Returns true if all components are in the [0, 1] range, as expected for normalised UV or NDC coordinates.
isZero¶
- bool isZero() const
Returns true if all four components are zero.
toString¶
- std::string toString() const
Returns a human-readable string like "Rect(10.000000, 20.000000, 100.000000, 50.000000)".