Base class for textured shapes with outline.
Shape is a drawable class that allows to define and display a custom convex shape on a render target.
It's only an abstract base, it needs to be specialized for concrete types of shapes (circle, rectangle, convex polygon, star, ...).
In addition to the attributes provided by the specialized shape classes, a shape always has the following attributes:
- a texture
- a texture rectangle
- a fill color
- an outline color
- an outline thickness
Each feature is optional, and can be disabled easily:
- the texture can be
None
- the fill/outline colors can be Transparent
- the outline thickness can be zero
You can write your own derived shape class, there are only two functions to override:
pointCount
must return the number of points of the shapepoint
must return the points of the shape
Attributes
- See also
- Companion
- object
- Graph
-
- Supertypes
- Known subtypes
-
trait CircleShapetrait RectangleShape
Members list
Value members
Abstract methods
Get a point of the shape.
Get a point of the shape.
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.
Value parameters
- index
-
Index of the point to get, in range [0 .. pointCount() - 1]
Attributes
- Returns
-
index-th point of the shape
- See also
Get the total number of points of the shape.
Get the total number of points of the shape.
Attributes
- Returns
-
Number of points of the shape
- See also
Concrete methods
Draw the object to a render target.
Draw the object to a render target.
This is a function that has to be implemented by the derived class to define how the drawable should be drawn.
Value parameters
- states
-
Current render states
- target
-
Render target to draw to
Attributes
- Definition Classes
Get the fill color of the shape.
Set the fill color of the shape.
Set the fill color of the shape.
This color is modulated (multiplied) with the shape's texture if any. It can be used to colorize the shape, or change its global opacity. You can use Transparent to make the inside of the shape transparent, and have the outline alone. By default, the shape's fill color is opaque white.
Value parameters
- color
-
New color of the shape
Attributes
- See also
Get the global (non-minimal) bounding rectangle of the entity.
Get the global (non-minimal) bounding rectangle of the entity.
The returned rectangle is in global coordinates, which means that it takes into account the transformations (translation, rotation, scale, ...) that are applied to the entity. In other words, this function returns the bounds of the shape in the global 2D world's coordinate system.
This function does not necessarily return the minimal bounding rectangle. It merely ensures that the returned rectangle covers all the vertices (but possibly more). This allows for a fast approximation of the bounds as a first check; you may want to use more precise checks on top of that.
Attributes
- Returns
-
Global bounding rectangle of the entity
Get the local bounding rectangle of the entity.
Get the local bounding rectangle of the entity.
The returned rectangle is in local coordinates, which means that it ignores the transformations (translation, rotation, scale, ...) that are applied to the entity. In other words, this function returns the bounds of the entity in the entity's coordinate system.
Attributes
- Returns
-
Local bounding rectangle of the entity
Get the outline color of the shape.
Get the outline color of the shape.
Attributes
- Returns
-
Outline color of the shape
- See also
Set the outline color of the shape.
Set the outline color of the shape.
By default, the shape's outline color is opaque white.
Value parameters
- color
-
New outline color of the shape
Attributes
- See also
Get the outline thickness of the shape.
Get the outline thickness of the shape.
Attributes
- Returns
-
Outline thickness of the shape
- See also
Set the thickness of the shape's outline.
Set the thickness of the shape's outline.
Note that negative values are allowed (so that the outline expands towards the center of the shape), and using zero disables the outline. By default, the outline thickness is 0.
Value parameters
- thickness
-
New outline thickness
Attributes
- See also
Get the source texture of the shape.
Get the source texture of the shape.
If the shape has no source texture, None
is returned.
Attributes
- Returns
-
Optional to the shape's texture
- See also
Get the sub-rectangle of the texture displayed by the shape.
Get the sub-rectangle of the texture displayed by the shape.
Attributes
- Returns
-
Texture rectangle of the shape
- See also
Set the sub-rectangle of the texture that the shape will display.
Set the sub-rectangle of the texture that the shape will display.
The texture rect is useful when you don't want to display the whole texture, but rather a part of it. By default, the texture rect covers the entire texture.
Value parameters
- rect
-
Rectangle defining the region of the texture to display
Attributes
- See also
Change the source texture of the shape.
Change the source texture of the shape.
The texture
argument refers to a texture that must exist as long as the shape uses it. Indeed, the shape doesn't store its own copy of the texture, but rather keeps a pointer to the one that you passed to this function. If the source texture is destroyed and the shape tries to use it, the behavior is undefined. texture
can be None
to disable texturing. If resetRect
is true, the TextureRect property of the shape is automatically adjusted to the size of the new texture. If it is false, the texture rect is left unchanged.
Value parameters
- resetRect
-
Should the texture rect be reset to the size of the new texture?
- texture
-
New texture
Attributes
- See also
Inherited methods
get the inverse of the combined transform of the object
get the inverse of the combined transform of the object
Attributes
- Returns
-
Inverse of the combined transformations applied to the object
- See also
- Inherited from:
- Transformable
Move the object by a given offset.
Move the object by a given offset.
This function adds to the current position of the object, unlike setPosition which overwrites it. Thus, it is equivalent to the following code:
import sfml.system.Vector2
val obj: Transformable = ???
val offset: Vector2[Float] = ???
obj.position = obj.position + offset
Value parameters
- offset
-
Offset
Attributes
- See also
- Inherited from:
- Transformable
Move the object by a given offset.
Move the object by a given offset.
This function adds to the current position of the object, unlike position_= which overwrites it. Thus, it is equivalent to the following code:
import sfml.system.Vector2
val obj: Transformable = ???
val offsetX, offsetY: Float = ???
val pos: Vector2[Float] = obj.position
obj.position = (pos.x + offsetX, pos.y + offsetY)
Value parameters
- offsetX
-
X offset
- offsetY
-
Y offset
Attributes
- See also
- Inherited from:
- Transformable
get the local origin of the object
get the local origin of the object
Attributes
- Returns
-
Current origin
- See also
- Inherited from:
- Transformable
set the local origin of the object
set the local origin of the object
The origin of an object defines the center point for all transformations (position, scale, rotation). The coordinates of this point must be relative to the top-left corner of the object, and ignore all transformations (position, scale, rotation). The default origin of a transformable object is (0, 0).
Value parameters
- origin
-
New origin
Attributes
- See also
- Inherited from:
- Transformable
set the local origin of the object
set the local origin of the object
The origin of an object defines the center point for all transformations (position, scale, rotation). The coordinates of this point must be relative to the top-left corner of the object, and ignore all transformations (position, scale, rotation). The default origin of a transformable object is (0, 0).
Value parameters
- x
-
X coordinate of the new origin
- y
-
Y coordinate of the new origin
Attributes
- See also
- Inherited from:
- Transformable
get the position of the object
get the position of the object
Attributes
- Returns
-
Current position
- See also
- Inherited from:
- Transformable
set the position of the object
set the position of the object
This function completely overwrites the previous position. See the move function to apply an offset based on the previous position instead. The default position of a transformable object is (0, 0).
Value parameters
- position
-
New position
Attributes
- See also
- Inherited from:
- Transformable
set the position of the object
set the position of the object
This function completely overwrites the previous position. See the move function to apply an offset based on the previous position instead. The default position of a transformable object is (0, 0).
Value parameters
- x
-
X coordinate of the new position
- y
-
Y coordinate of the new position
Attributes
- See also
- Inherited from:
- Transformable
Rotate the object.
Rotate the object.
This function adds to the current rotation of the object, unlike setRotation which overwrites it. Thus, it is equivalent to the following code:
val obj: Transformable = ???
val angle: Float = ???
obj.rotation = obj.rotation + angle
Value parameters
- angle
-
Angle of rotation, in degrees
Attributes
- Inherited from:
- Transformable
get the orientation of the object
get the orientation of the object
The rotation is always in the range [0, 360].
Attributes
- Returns
-
Current rotation, in degrees
- See also
- Inherited from:
- Transformable
set the orientation of the object
set the orientation of the object
This function completely overwrites the previous rotation. See the rotate function to add an angle based on the previous rotation instead. The default rotation of a transformable object is 0.
Value parameters
- angle
-
New rotation, in degrees
Attributes
- See also
- Inherited from:
- Transformable
get the current scale of the object
get the current scale of the object
Attributes
- Returns
-
Current scale factors
- See also
- Inherited from:
- Transformable
Scale the object.
Scale the object.
This function multiplies the current scale of the object, unlike setScale which overwrites it. Thus, it is equivalent to the following code:
import sfml.system.Vector2
val obj: Transformable = ???
val factor: Vector2[Float] = ???
val scale: Vector2[Float] = obj.scale
obj.scale = (scale.x * factor.x, scale.y * factor.y)
Value parameters
- factor
-
Scale factors
Attributes
- See also
- Inherited from:
- Transformable
Scale the object.
Scale the object.
This function multiplies the current scale of the object, unlike setScale which overwrites it. Thus, it is equivalent to the following code:
import sfml.system.Vector2
val obj: Transformable = ???
val factorX, factorY: Float = ???
val scale: Vector2[Float] = obj.scale
obj.scale = (scale.x + factorX, scale.y + factorY)
Value parameters
- factorX
-
Horizontal scale factor
- factorY
-
Vertical scale factor
Attributes
- See also
- Inherited from:
- Transformable
set the scale factors of the object
set the scale factors of the object
This function completely overwrites the previous scale. See the scale function to add a factor based on the previous scale instead. The default scale of a transformable object is (1, 1).
Value parameters
- factors
-
New scale factors
Attributes
- See also
- Inherited from:
- Transformable
set the scale factors of the object
set the scale factors of the object
This function completely overwrites the previous scale. See the scale function to add a factor based on the previous scale instead. The default scale of a transformable object is (1, 1).
Value parameters
- factorX
-
New horizontal scale factor
- factorY
-
New vertical scale factor
Attributes
- See also
- Inherited from:
- Transformable
get the combined transform of the object
get the combined transform of the object
Attributes
- Returns
-
Transform combining the position/rotation/scale/origin of the object
- See also
- Inherited from:
- Transformable