SFML
Simple and Fast Multimedia Library
Loading...
Searching...
No Matches
sf::CircleShape Class Reference

Specialized shape representing a circle. More...

#include <CircleShape.hpp>

Inheritance diagram for sf::CircleShape:
[legend]

Public Member Functions

 CircleShape (float radius=0, std::size_t pointCount=30)
 Default constructor.
void setRadius (float radius)
 Set the radius of the circle.
float getRadius () const
 Get the radius of the circle.
void setPointCount (std::size_t count)
 Set the number of points of the circle.
std::size_t getPointCount () const override
 Get the number of points of the circle.
Vector2f getPoint (std::size_t index) const override
 Get a point of the circle.
Vector2f getGeometricCenter () const override
 Get the geometric center of the circle.
Public Member Functions inherited from sf::Shape
void setTexture (const Texture *texture, bool resetRect=false)
 Change the source texture of the shape.
void setTextureRect (const IntRect &rect)
 Set the sub-rectangle of the texture that the shape will display.
void setFillColor (Color color)
 Set the fill color of the shape.
void setOutlineColor (Color color)
 Set the outline color of the shape.
void setOutlineThickness (float thickness)
 Set the thickness of the shape's outline.
const TexturegetTexture () const
 Get the source texture of the shape.
const IntRectgetTextureRect () const
 Get the sub-rectangle of the texture displayed by the shape.
Color getFillColor () const
 Get the fill color of the shape.
Color getOutlineColor () const
 Get the outline color of the shape.
float getOutlineThickness () const
 Get the outline thickness of the shape.
FloatRect getLocalBounds () const
 Get the local bounding rectangle of the entity.
FloatRect getGlobalBounds () const
 Get the global (non-minimal) bounding rectangle of the entity.
Public Member Functions inherited from sf::Drawable
virtual ~Drawable ()=default
 Virtual destructor.
Public Member Functions inherited from sf::Transformable
 Transformable ()=default
 Default constructor.
virtual ~Transformable ()=default
 Virtual destructor.
void setPosition (Vector2f position)
 set the position of the object
void setRotation (Angle angle)
 set the orientation of the object
void setScale (Vector2f factors)
 set the scale factors of the object
void setOrigin (Vector2f origin)
 set the local origin of the object
Vector2f getPosition () const
 get the position of the object
Angle getRotation () const
 get the orientation of the object
Vector2f getScale () const
 get the current scale of the object
Vector2f getOrigin () const
 get the local origin of the object
void move (Vector2f offset)
 Move the object by a given offset.
void rotate (Angle angle)
 Rotate the object.
void scale (Vector2f factor)
 Scale the object.
const TransformgetTransform () const
 get the combined transform of the object
const TransformgetInverseTransform () const
 get the inverse of the combined transform of the object

Additional Inherited Members

Protected Member Functions inherited from sf::Shape
void update ()
 Recompute the internal geometry of the shape.

Detailed Description

Specialized shape representing a circle.

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:

circle.setRadius(150);
circle.setPosition({10, 20});
...
window.draw(circle);
Specialized shape representing a circle.
Definition CircleShape.hpp:46
void setRadius(float radius)
Set the radius of the circle.
static const Color Red
Red predefined color.
Definition Color.hpp:84
void setOutlineThickness(float thickness)
Set the thickness of the shape's outline.
void setOutlineColor(Color color)
Set the outline color of the shape.
void setPosition(Vector2f position)
set the position of the object

Since the graphics card can't draw perfect circles, we have to fake them with multiple triangles connected to each other. The "points count" property of sf::CircleShape defines how many of these triangles to use, and therefore defines the quality of the circle.

The number of points can also be used for another purpose; with small numbers you can create any regular polygon shape: equilateral triangle, square, pentagon, hexagon, ...

See also
sf::Shape, sf::RectangleShape, sf::ConvexShape

Constructor & Destructor Documentation

◆ CircleShape()

sf::CircleShape::CircleShape ( float radius = 0,
std::size_t pointCount = 30 )
explicit

Default constructor.

Parameters
radiusRadius of the circle
pointCountNumber of points composing the circle

Member Function Documentation

◆ getGeometricCenter()

Vector2f sf::CircleShape::getGeometricCenter ( ) const
nodiscardoverridevirtual

Get the geometric center of the circle.

The returned point is in local coordinates, that is, the shape's transforms (position, rotation, scale) are not taken into account.

Returns
The geometric center of the shape

Reimplemented from sf::Shape.

◆ getPoint()

Vector2f sf::CircleShape::getPoint ( std::size_t index) const
nodiscardoverridevirtual

Get a point of the circle.

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.

Parameters
indexIndex of the point to get, in range [0 .. getPointCount() - 1]
Returns
index-th point of the shape

Implements sf::Shape.

◆ getPointCount()

std::size_t sf::CircleShape::getPointCount ( ) const
nodiscardoverridevirtual

Get the number of points of the circle.

Returns
Number of points of the circle
See also
setPointCount

Implements sf::Shape.

◆ getRadius()

float sf::CircleShape::getRadius ( ) const
nodiscard

Get the radius of the circle.

Returns
Radius of the circle
See also
setRadius

◆ setPointCount()

void sf::CircleShape::setPointCount ( std::size_t count)

Set the number of points of the circle.

Parameters
countNew number of points of the circle
See also
getPointCount

◆ setRadius()

void sf::CircleShape::setRadius ( float radius)

Set the radius of the circle.

Parameters
radiusNew radius of the circle
See also
getRadius

The documentation for this class was generated from the following file: