Functions
Sprite.h File Reference
#include <SFML/Graphics/Export.h>
#include <SFML/Graphics/BlendMode.h>
#include <SFML/Graphics/Color.h>
#include <SFML/Graphics/Rect.h>
#include <SFML/Graphics/Transform.h>
#include <SFML/Graphics/Types.h>
#include <SFML/System/Vector2.h>

Go to the source code of this file.

Functions

CSFML_GRAPHICS_API sfSpritesfSprite_create (void)
 Create a new sprite. More...
 
CSFML_GRAPHICS_API sfSpritesfSprite_copy (const sfSprite *sprite)
 Copy an existing sprite. More...
 
CSFML_GRAPHICS_API void sfSprite_destroy (sfSprite *sprite)
 Destroy an existing sprite. More...
 
CSFML_GRAPHICS_API void sfSprite_setPosition (sfSprite *sprite, sfVector2f position)
 Set the position of a sprite. More...
 
CSFML_GRAPHICS_API void sfSprite_setRotation (sfSprite *sprite, float angle)
 Set the orientation of a sprite. More...
 
CSFML_GRAPHICS_API void sfSprite_setScale (sfSprite *sprite, sfVector2f scale)
 Set the scale factors of a sprite. More...
 
CSFML_GRAPHICS_API void sfSprite_setOrigin (sfSprite *sprite, sfVector2f origin)
 Set the local origin of a sprite. More...
 
CSFML_GRAPHICS_API sfVector2f sfSprite_getPosition (const sfSprite *sprite)
 Get the position of a sprite. More...
 
CSFML_GRAPHICS_API float sfSprite_getRotation (const sfSprite *sprite)
 Get the orientation of a sprite. More...
 
CSFML_GRAPHICS_API sfVector2f sfSprite_getScale (const sfSprite *sprite)
 Get the current scale of a sprite. More...
 
CSFML_GRAPHICS_API sfVector2f sfSprite_getOrigin (const sfSprite *sprite)
 Get the local origin of a sprite. More...
 
CSFML_GRAPHICS_API void sfSprite_move (sfSprite *sprite, sfVector2f offset)
 Move a sprite by a given offset. More...
 
CSFML_GRAPHICS_API void sfSprite_rotate (sfSprite *sprite, float angle)
 Rotate a sprite. More...
 
CSFML_GRAPHICS_API void sfSprite_scale (sfSprite *sprite, sfVector2f factors)
 Scale a sprite. More...
 
CSFML_GRAPHICS_API sfTransform sfSprite_getTransform (const sfSprite *sprite)
 Get the combined transform of a sprite. More...
 
CSFML_GRAPHICS_API sfTransform sfSprite_getInverseTransform (const sfSprite *sprite)
 Get the inverse of the combined transform of a sprite. More...
 
CSFML_GRAPHICS_API void sfSprite_setTexture (sfSprite *sprite, const sfTexture *texture, sfBool resetRect)
 Change the source texture of a sprite. More...
 
CSFML_GRAPHICS_API void sfSprite_setTextureRect (sfSprite *sprite, sfIntRect rectangle)
 Set the sub-rectangle of the texture that a sprite will display. More...
 
CSFML_GRAPHICS_API void sfSprite_setColor (sfSprite *sprite, sfColor color)
 Set the global color of a sprite. More...
 
CSFML_GRAPHICS_API const sfTexturesfSprite_getTexture (const sfSprite *sprite)
 Get the source texture of a sprite. More...
 
CSFML_GRAPHICS_API sfIntRect sfSprite_getTextureRect (const sfSprite *sprite)
 Get the sub-rectangle of the texture displayed by a sprite. More...
 
CSFML_GRAPHICS_API sfColor sfSprite_getColor (const sfSprite *sprite)
 Get the global color of a sprite. More...
 
CSFML_GRAPHICS_API sfFloatRect sfSprite_getLocalBounds (const sfSprite *sprite)
 Get the local bounding rectangle of a sprite. More...
 
CSFML_GRAPHICS_API sfFloatRect sfSprite_getGlobalBounds (const sfSprite *sprite)
 Get the global bounding rectangle of a sprite. More...
 

Function Documentation

◆ sfSprite_copy()

CSFML_GRAPHICS_API sfSprite* sfSprite_copy ( const sfSprite sprite)

Copy an existing sprite.

Parameters
spriteSprite to copy
Returns
Copied object

◆ sfSprite_create()

CSFML_GRAPHICS_API sfSprite* sfSprite_create ( void  )

Create a new sprite.

Returns
A new sfSprite object, or NULL if it failed

◆ sfSprite_destroy()

CSFML_GRAPHICS_API void sfSprite_destroy ( sfSprite sprite)

Destroy an existing sprite.

Parameters
spriteSprite to delete

◆ sfSprite_getColor()

CSFML_GRAPHICS_API sfColor sfSprite_getColor ( const sfSprite sprite)

Get the global color of a sprite.

Parameters
spriteSprite object
Returns
Global color of the sprite

◆ sfSprite_getGlobalBounds()

CSFML_GRAPHICS_API sfFloatRect sfSprite_getGlobalBounds ( const sfSprite sprite)

Get the global bounding rectangle of a sprite.

The returned rectangle is in global coordinates, which means that it takes in account the transformations (translation, rotation, scale, ...) that are applied to the entity. In other words, this function returns the bounds of the sprite in the global 2D world's coordinate system.

Parameters
spriteSprite object
Returns
Global bounding rectangle of the entity

◆ sfSprite_getInverseTransform()

CSFML_GRAPHICS_API sfTransform sfSprite_getInverseTransform ( const sfSprite sprite)

Get the inverse of the combined transform of a sprite.

Parameters
spriteSprite object
Returns
Inverse of the combined transformations applied to the object

◆ sfSprite_getLocalBounds()

CSFML_GRAPHICS_API sfFloatRect sfSprite_getLocalBounds ( const sfSprite sprite)

Get the local bounding rectangle of a sprite.

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.

Parameters
spriteSprite object
Returns
Local bounding rectangle of the entity

◆ sfSprite_getOrigin()

CSFML_GRAPHICS_API sfVector2f sfSprite_getOrigin ( const sfSprite sprite)

Get the local origin of a sprite.

Parameters
spriteSprite object
Returns
Current origin

◆ sfSprite_getPosition()

CSFML_GRAPHICS_API sfVector2f sfSprite_getPosition ( const sfSprite sprite)

Get the position of a sprite.

Parameters
spriteSprite object
Returns
Current position

◆ sfSprite_getRotation()

CSFML_GRAPHICS_API float sfSprite_getRotation ( const sfSprite sprite)

Get the orientation of a sprite.

The rotation is always in the range [0, 360].

Parameters
spriteSprite object
Returns
Current rotation, in degrees

◆ sfSprite_getScale()

CSFML_GRAPHICS_API sfVector2f sfSprite_getScale ( const sfSprite sprite)

Get the current scale of a sprite.

Parameters
spriteSprite object
Returns
Current scale factors

◆ sfSprite_getTexture()

CSFML_GRAPHICS_API const sfTexture* sfSprite_getTexture ( const sfSprite sprite)

Get the source texture of a sprite.

If the sprite has no source texture, a NULL pointer is returned. The returned pointer is const, which means that you can't modify the texture when you retrieve it with this function.

Parameters
spriteSprite object
Returns
Pointer to the sprite's texture

◆ sfSprite_getTextureRect()

CSFML_GRAPHICS_API sfIntRect sfSprite_getTextureRect ( const sfSprite sprite)

Get the sub-rectangle of the texture displayed by a sprite.

Parameters
spriteSprite object
Returns
Texture rectangle of the sprite

◆ sfSprite_getTransform()

CSFML_GRAPHICS_API sfTransform sfSprite_getTransform ( const sfSprite sprite)

Get the combined transform of a sprite.

Parameters
spriteSprite object
Returns
Transform combining the position/rotation/scale/origin of the object

◆ sfSprite_move()

CSFML_GRAPHICS_API void sfSprite_move ( sfSprite sprite,
sfVector2f  offset 
)

Move a sprite by a given offset.

This function adds to the current position of the object, unlike sfSprite_setPosition which overwrites it.

Parameters
spriteSprite object
offsetOffset

◆ sfSprite_rotate()

CSFML_GRAPHICS_API void sfSprite_rotate ( sfSprite sprite,
float  angle 
)

Rotate a sprite.

This function adds to the current rotation of the object, unlike sfSprite_setRotation which overwrites it.

Parameters
spriteSprite object
angleAngle of rotation, in degrees

◆ sfSprite_scale()

CSFML_GRAPHICS_API void sfSprite_scale ( sfSprite sprite,
sfVector2f  factors 
)

Scale a sprite.

This function multiplies the current scale of the object, unlike sfSprite_setScale which overwrites it.

Parameters
spriteSprite object
factorsScale factors

◆ sfSprite_setColor()

CSFML_GRAPHICS_API void sfSprite_setColor ( sfSprite sprite,
sfColor  color 
)

Set the global color of a sprite.

This color is modulated (multiplied) with the sprite's texture. It can be used to colorize the sprite, or change its global opacity. By default, the sprite's color is opaque white.

Parameters
spriteSprite object
colorNew color of the sprite

◆ sfSprite_setOrigin()

CSFML_GRAPHICS_API void sfSprite_setOrigin ( sfSprite sprite,
sfVector2f  origin 
)

Set the local origin of a sprite.

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 sprite Sprite object is (0, 0).

Parameters
spriteSprite object
originNew origin

◆ sfSprite_setPosition()

CSFML_GRAPHICS_API void sfSprite_setPosition ( sfSprite sprite,
sfVector2f  position 
)

Set the position of a sprite.

This function completely overwrites the previous position. See sfSprite_move to apply an offset based on the previous position instead. The default position of a sprite Sprite object is (0, 0).

Parameters
spriteSprite object
positionNew position

◆ sfSprite_setRotation()

CSFML_GRAPHICS_API void sfSprite_setRotation ( sfSprite sprite,
float  angle 
)

Set the orientation of a sprite.

This function completely overwrites the previous rotation. See sfSprite_rotate to add an angle based on the previous rotation instead. The default rotation of a sprite Sprite object is 0.

Parameters
spriteSprite object
angleNew rotation, in degrees

◆ sfSprite_setScale()

CSFML_GRAPHICS_API void sfSprite_setScale ( sfSprite sprite,
sfVector2f  scale 
)

Set the scale factors of a sprite.

This function completely overwrites the previous scale. See sfSprite_scale to add a factor based on the previous scale instead. The default scale of a sprite Sprite object is (1, 1).

Parameters
spriteSprite object
scaleNew scale factors

◆ sfSprite_setTexture()

CSFML_GRAPHICS_API void sfSprite_setTexture ( sfSprite sprite,
const sfTexture texture,
sfBool  resetRect 
)

Change the source texture of a sprite.

The texture argument refers to a texture that must exist as long as the sprite uses it. Indeed, the sprite 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 sprite tries to use it, the behaviour is undefined. If resetRect is true, the TextureRect property of the sprite is automatically adjusted to the size of the new texture. If it is false, the texture rect is left unchanged.

Parameters
spriteSprite object
textureNew texture
resetRectShould the texture rect be reset to the size of the new texture?

◆ sfSprite_setTextureRect()

CSFML_GRAPHICS_API void sfSprite_setTextureRect ( sfSprite sprite,
sfIntRect  rectangle 
)

Set the sub-rectangle of the texture that a sprite 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.

Parameters
spriteSprite object
rectangleRectangle defining the region of the texture to display