class

SF::RectangleShape

Inherits SF::Shape / SF::Drawable / SF::Transformable / Reference / Object

Specialized shape representing a rectangle

This class inherits all the functions of SF::Transformable (position, rotation, scale, bounds, ...) as well as the functions of SF::Shape (outline, color, texture, ...).

Usage example:

rectangle = SF::RectangleShape.new
rectangle.size = SF.vector2f(100, 50)
rectangle.outline_color = SF::Color::Red
rectangle.outline_thickness = 5
rectangle.position = {10, 20}
# [...]
window.draw rectangle

See also: SF::Shape, SF::CircleShape, SF::ConvexShape

Constructors

new(size : Vector2 | Tuple = Vector2.new(0, 0))

Default constructor

  • size - Size of the rectangle
Source

Instance methods

dup

Returns a shallow copy of this object.

This allocates a new object and copies the contents of self into it.

Source
finalize

Virtual destructor

Source
get_point(index : Int) : Vector2f

Get a point of the rectangle

The returned point is in local coordinates, that is, the shape's transforms (position, rotation, scale) are not taken into account. The result is undefined if index is out of the valid range.

  • index - Index of the point to get, in range 0..3

Returns: index-th point of the shape

Source
point_count

Get the number of points defining the shape

Returns: Number of points of the shape. For rectangle shapes, this number is always 4.

Source
size

Get the size of the rectangle

Returns: Size of the rectangle

See also: size=

Source
size=(size : Vector2 | Tuple)

Set the size of the rectangle

  • size - New size of the rectangle

See also: size

Source