# sf::Sprite Class Reference

Sprite defines a sprite : texture, transformations, color, and draw on screen. More...

`#include <Sprite.hpp>`

Inheritance diagram for sf::Sprite:

List of all members.

## Public Member Functions

| Sprite ()
| Default constructor.
| Sprite (const Image &Img, const Vector2f &Position=Vector2f(0, 0), const Vector2f &Scale=Vector2f(1, 1), float Rotation=0.f, const Color &Col=Color(255, 255, 255, 255))
| Construct the sprite from a source image.
void | SetImage (const Image &Img)
| Change the image of the sprite.
void | SetSubRect (const IntRect &SubRect)
| Set the sub-rectangle of the sprite inside the source image.
void | Resize (float Width, float Height)
| Resize the sprite (by changing its scale factors) (take 2 values).
void | Resize (const Vector2f &Size)
| Resize the sprite (by changing its scale factors) (take a 2D vector).
void | FlipX (bool Flipped)
| Flip the sprite horizontally.
void | FlipY (bool Flipped)
| Flip the sprite vertically.
const Image * | GetImage () const
| Get the source image of the sprite.
const IntRect & | GetSubRect () const
| Get the sub-rectangle of the sprite inside the source image.
Vector2f | GetSize () const
| Get the sprite size.
Color | GetPixel (unsigned int X, unsigned int Y) const
| Get the color of a given pixel in the sprite (point is in local coordinates).
void | SetPosition (float X, float Y)
| Set the position of the object (take 2 values).
void | SetPosition (const Vector2f &Position)
| Set the position of the object (take a 2D vector).
void | SetX (float X)
| Set the X position of the object.
void | SetY (float Y)
| Set the Y position of the object.
void | SetScale (float ScaleX, float ScaleY)
| Set the scale of the object (take 2 values).
void | SetScale (const Vector2f &Scale)
| Set the scale of the object (take a 2D vector).
void | SetScaleX (float FactorX)
| Set the X scale factor of the object.
void | SetScaleY (float FactorY)
| Set the Y scale factor of the object.
void | SetCenter (float CenterX, float CenterY)
| Set the center of the object, in coordinates relative to the top-left of the object (take 2 values).
void | SetCenter (const Vector2f &Center)
| Set the center of the object, in coordinates relative to the top-left of the object (take a 2D vector).
void | SetRotation (float Rotation)
| Set the orientation of the object.
void | SetColor (const Color &Col)
| Set the color of the object.
void | SetBlendMode (Blend::Mode Mode)
| Set the blending mode for the object.
const Vector2f & | GetPosition () const
| Get the position of the object.
const Vector2f & | GetScale () const
| Get the current scale of the object.
const Vector2f & | GetCenter () const
| Get the center of the object.
float | GetRotation () const
| Get the orientation of the object.
const Color & | GetColor () const
| Get the color of the object.
Blend::Mode | GetBlendMode () const
| Get the current blending mode.
void | Move (float OffsetX, float OffsetY)
| Move the object of a given offset (take 2 values).
void | Move (const Vector2f &Offset)
| Move the object of a given offset (take a 2D vector).
void | Scale (float FactorX, float FactorY)
| Scale the object (take 2 values).
void | Scale (const Vector2f &Factor)
| Scale the object (take a 2D vector).
void | Rotate (float Angle)
| Rotate the object.
sf::Vector2f | TransformToLocal (const sf::Vector2f &Point) const
| Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's center, translation, rotation and scale to the point).
sf::Vector2f | TransformToGlobal (const sf::Vector2f &Point) const
| Transform a point from local coordinates into global coordinates (ie it applies the object's center, translation, rotation and scale to the point).

## Protected Member Functions

virtual void | Render (RenderTarget &Target) const
| /see Drawable::Render
const Matrix3 & | GetMatrix () const
| Get the transform matrix of the drawable.
const Matrix3 & | GetInverseMatrix () const
| Get the inverse transform matrix of the drawable.

## Detailed Description

Sprite defines a sprite : texture, transformations, color, and draw on screen.

Definition at line 44 of file Sprite.hpp.

## Constructor & Destructor Documentation

sf::Sprite::Sprite | ( |  | ) |

Default constructor.

Definition at line 38 of file Sprite.cpp.

sf::Sprite::Sprite | ( | const Image & | Img,
|  | const Vector2f & | Position = `Vector2f(0, 0)`,
|  | const Vector2f & | Scale = `Vector2f(1, 1)`,
|  | float | Rotation = `0.f`,
|  | const Color & | Col = `Color(255, 255, 255, 255)` |
| ) |  |  | `[explicit]`

Construct the sprite from a source image.

Parameters:

  | Img | : Image of the sprite
  | Position | : Position of the sprite (0, 0 by default)
  | Scale | : Scale factor (1, 1 by default)
  | Rotation | : Orientation, in degrees (0 by default)
  | Col | : Color of the sprite (white by default)

Definition at line 50 of file Sprite.cpp.

## Member Function Documentation

void sf::Sprite::FlipX | ( | bool | Flipped | ) |

Flip the sprite horizontally.

Parameters:

  | Flipped | : True to flip the sprite

Definition at line 112 of file Sprite.cpp.

void sf::Sprite::FlipY | ( | bool | Flipped | ) |

Flip the sprite vertically.

Parameters:

  | Flipped | : True to flip the sprite

Definition at line 121 of file Sprite.cpp.

Blend::Mode sf::Drawable::GetBlendMode | ( |  | ) | const`[inherited]`

Get the current blending mode.

Returns:
  Current blending mode

Definition at line 258 of file Drawable.cpp.

const Vector2f & sf::Drawable::GetCenter | ( |  | ) | const`[inherited]`

Get the center of the object.

Returns:
  Current position of the center

Definition at line 231 of file Drawable.cpp.

const Color & sf::Drawable::GetColor | ( |  | ) | const`[inherited]`

Get the color of the object.

Returns:
  Current color

Definition at line 249 of file Drawable.cpp.

const Image * sf::Sprite::GetImage | ( |  | ) | const

Get the source image of the sprite.

Returns:
  Pointer to the image (can be NULL)

Definition at line 130 of file Sprite.cpp.

const Matrix3 & sf::Drawable::GetInverseMatrix | ( |  | ) | const`[protected, inherited]`

Get the inverse transform matrix of the drawable.

Returns:
  Inverse transform matrix

Definition at line 350 of file Drawable.cpp.

const Matrix3 & sf::Drawable::GetMatrix | ( |  | ) | const`[protected, inherited]`

Get the transform matrix of the drawable.

Returns:
  Transform matrix

Definition at line 334 of file Drawable.cpp.

Color sf::Sprite::GetPixel | ( | unsigned int | X,
|  | unsigned int | Y |
| ) |  |  | const

Get the color of a given pixel in the sprite (point is in local coordinates).

Get the color of a given pixel in the sprite (point is in local coordinates).

Parameters:

  | X | : X coordinate of the pixel to get
  | Y | : Y coordinate of the pixel to get

Returns:
  Color of pixel (X, Y)

Definition at line 158 of file Sprite.cpp.

const Vector2f & sf::Drawable::GetPosition | ( |  | ) | const`[inherited]`

Get the position of the object.

Returns:
  Current position

Definition at line 213 of file Drawable.cpp.

float sf::Drawable::GetRotation | ( |  | ) | const`[inherited]`

Get the orientation of the object.

Rotation is always in the range [0, 360]

Returns:
  Current rotation, in degrees

Definition at line 240 of file Drawable.cpp.

const Vector2f & sf::Drawable::GetScale | ( |  | ) | const`[inherited]`

Get the current scale of the object.

Returns:
  Current scale factor (always positive)

Definition at line 222 of file Drawable.cpp.

Vector2f sf::Sprite::GetSize | ( |  | ) | const

Get the sprite size.

Returns:
  Size of the sprite

Definition at line 148 of file Sprite.cpp.

const IntRect & sf::Sprite::GetSubRect | ( |  | ) | const

Get the sub-rectangle of the sprite inside the source image.

Returns:
  Sub-rectangle

Definition at line 139 of file Sprite.cpp.

void sf::Drawable::Move | ( | const Vector2f & | Offset | ) | `[inherited]`

Move the object of a given offset (take a 2D vector).

Parameters:

  | Offset | : Amount of units to move the object of

Definition at line 278 of file Drawable.cpp.

void sf::Drawable::Move | ( | float | OffsetX,
|  | float | OffsetY |
| ) |  |  | `[inherited]`

Move the object of a given offset (take 2 values).

Parameters:

  | OffsetX | : X offset
  | OffsetY | : Y offset

Definition at line 268 of file Drawable.cpp.

void sf::Sprite::Render | ( | RenderTarget & | Target | ) | const`[protected, virtual]`

/see Drawable::Render

/see sfDrawable::Render

Implements sf::Drawable.

Definition at line 180 of file Sprite.cpp.

void sf::Sprite::Resize | ( | const Vector2f & | Size | ) |

Resize the sprite (by changing its scale factors) (take a 2D vector).

Resize the object (by changing its scale factors) (take a 2D vector) The default size is defined by the subrect.

The default size is defined by the subrect

Parameters:

  | Size | : New size (both coordinates must be strictly positive)

Definition at line 103 of file Sprite.cpp.

void sf::Sprite::Resize | ( | float | Width,
|  | float | Height |
| ) |  |  |

Resize the sprite (by changing its scale factors) (take 2 values).

The default size is defined by the subrect

Parameters:

  | Width | : New width (must be strictly positive)
  | Height | : New height (must be strictly positive)

The default size is defined by the subrect

Definition at line 89 of file Sprite.cpp.

void sf::Drawable::Rotate | ( | float | Angle | ) | `[inherited]`

Rotate the object.

Parameters:

  | Angle | : Angle of rotation, in degrees

Definition at line 306 of file Drawable.cpp.

void sf::Drawable::Scale | ( | const Vector2f & | Factor | ) | `[inherited]`

Scale the object (take a 2D vector).

Parameters:

  | Factor | : Scaling factors (both values must be strictly positive)

Definition at line 297 of file Drawable.cpp.

void sf::Drawable::Scale | ( | float | FactorX,
|  | float | FactorY |
| ) |  |  | `[inherited]`

Scale the object (take 2 values).

Parameters:

  | FactorX | : Scaling factor on X (must be strictly positive)
  | FactorY | : Scaling factor on Y (must be strictly positive)

Definition at line 287 of file Drawable.cpp.

void sf::Drawable::SetBlendMode | ( | Blend::Mode | Mode | ) | `[inherited]`

Set the blending mode for the object.

The default blend mode is Blend::Alpha

Parameters:

  | Mode | : New blending mode

The default blend mode is Blend::Alpha

Definition at line 204 of file Drawable.cpp.

void sf::Drawable::SetCenter | ( | const Vector2f & | Center | ) | `[inherited]`

Set the center of the object, in coordinates relative to the top-left of the object (take a 2D vector).

Set the center of the object, in coordinates relative to the top-left of the object (take a 2D vector).

The default center is (0, 0)

Parameters:

  | Center | : New center

The default center is (0, 0)

Definition at line 171 of file Drawable.cpp.

void sf::Drawable::SetCenter | ( | float | CenterX,
|  | float | CenterY |
| ) |  |  | `[inherited]`

Set the center of the object, in coordinates relative to the top-left of the object (take 2 values).

Set the center of the object, in coordinates relative to the top-left of the object (take 2 values).

The default center is (0, 0)

Parameters:

  | CenterX | : X coordinate of the center
  | CenterY | : Y coordinate of the center

The default center is (0, 0)

Definition at line 157 of file Drawable.cpp.

void sf::Drawable::SetColor | ( | const Color & | Col | ) | `[inherited]`

Set the color of the object.

The default color is white

Parameters:

  | Col | : New color

The default color is white

Definition at line 194 of file Drawable.cpp.

void sf::Sprite::SetImage | ( | const Image & | Img | ) |

Change the image of the sprite.

Set the image of the sprite.

Parameters:

  | Img | : New image

Definition at line 63 of file Sprite.cpp.

void sf::Drawable::SetPosition | ( | const Vector2f & | Position | ) | `[inherited]`

Set the position of the object (take a 2D vector).

Parameters:

  | Position | : New position

Definition at line 75 of file Drawable.cpp.

void sf::Drawable::SetPosition | ( | float | X,
|  | float | Y |
| ) |  |  | `[inherited]`

Set the position of the object (take 2 values).

Parameters:

  | X | : New X coordinate
  | Y | : New Y coordinate

Definition at line 65 of file Drawable.cpp.

void sf::Drawable::SetRotation | ( | float | Rotation | ) | `[inherited]`

Set the orientation of the object.

Parameters:

  | Rotation | : Angle of rotation, in degrees

Definition at line 180 of file Drawable.cpp.

void sf::Drawable::SetScale | ( | const Vector2f & | Scale | ) | `[inherited]`

Set the scale of the object (take a 2D vector).

Parameters:

  | Scale | : New scale (both values must be strictly positive)

Definition at line 117 of file Drawable.cpp.

void sf::Drawable::SetScale | ( | float | ScaleX,
|  | float | ScaleY |
| ) |  |  | `[inherited]`

Set the scale of the object (take 2 values).

Parameters:

  | ScaleX | : New horizontal scale (must be strictly positive)
  | ScaleY | : New vertical scale (must be strictly positive)

Definition at line 107 of file Drawable.cpp.

void sf::Drawable::SetScaleX | ( | float | FactorX | ) | `[inherited]`

Set the X scale factor of the object.

Parameters:

  | X | : New X scale factor

Definition at line 127 of file Drawable.cpp.

void sf::Drawable::SetScaleY | ( | float | FactorY | ) | `[inherited]`

Set the Y scale factor of the object.

Parameters:

  | Y | : New Y scale factor

Definition at line 141 of file Drawable.cpp.

void sf::Sprite::SetSubRect | ( | const IntRect & | SubRect | ) |

Set the sub-rectangle of the sprite inside the source image.

By default, the subrect covers the entire source image

Parameters:

  | SubRect | : New sub-rectangle

Definition at line 79 of file Sprite.cpp.

void sf::Drawable::SetX | ( | float | X | ) | `[inherited]`

Set the X position of the object.

Parameters:

  | X | : New X coordinate

Definition at line 85 of file Drawable.cpp.

void sf::Drawable::SetY | ( | float | Y | ) | `[inherited]`

Set the Y position of the object.

Parameters:

  | Y | : New Y coordinate

Definition at line 96 of file Drawable.cpp.

sf::Vector2f sf::Drawable::TransformToGlobal | ( | const sf::Vector2f & | Point | ) | const`[inherited]`

Transform a point from local coordinates into global coordinates (ie it applies the object's center, translation, rotation and scale to the point).

Transform a point from local coordinates into global coordinates (ie it applies the object's center, translation, rotation and scale to the point).

Parameters:

  | Point | : Point to transform

Returns:
  Transformed point

Definition at line 325 of file Drawable.cpp.

sf::Vector2f sf::Drawable::TransformToLocal | ( | const sf::Vector2f & | Point | ) | const`[inherited]`

Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's center, translation, rotation and scale to the point).

Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's center, translation, rotation and scale to the point).

Parameters:

  | Point | : Point to transform

Returns:
  Transformed point

Definition at line 316 of file Drawable.cpp.

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

- Sprite.hpp
- Sprite.cpp