sf::Sprite Class Reference

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

#include <Sprite.hpp>

Inheritance diagram for sf::Sprite:
sf::Drawable

List of all members.

Public Member Functions

 Sprite ()
 Default constructor.
 Sprite (const Image &image, const Vector2f &position=Vector2f(0, 0), const Vector2f &scale=Vector2f(1, 1), float rotation=0.f, const Color &color=Color(255, 255, 255, 255))
 Construct the sprite from a source image.
void SetImage (const Image &image, bool adjustToNewSize=false)
 Change the image of the sprite.
void SetSubRect (const IntRect &rectangle)
 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 ImageGetImage () const
 Get the source image of the sprite.
const IntRectGetSubRect () 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 factorX, float factorY)
 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 factor)
 Set the X scale factor of the object.
void SetScaleY (float factor)
 Set the Y scale factor of the object.
void SetOrigin (float x, float y)
 Set the local origin of the object, in coordinates relative to the top-left of the object (take 2 values).
void SetOrigin (const Vector2f &origin)
 Set the local origin of the object, in coordinates relative to the top-left of the object (take a 2D vector).
void SetRotation (float angle)
 Set the orientation of the object.
void SetColor (const Color &color)
 Set the color of the object.
void SetBlendMode (Blend::Mode mode)
 Set the blending mode for the object.
const Vector2fGetPosition () const
 Get the position of the object.
const Vector2fGetScale () const
 Get the current scale of the object.
const Vector2fGetOrigin () const
 Get the local origin of the object.
float GetRotation () const
 Get the orientation of the object.
const ColorGetColor () 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.
Vector2f TransformToLocal (const Vector2f &point) const
 Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's origin, translation, rotation and scale to the point).
Vector2f TransformToGlobal (const Vector2f &point) const
 Transform a point from local coordinates into global coordinates (ie it applies the object's origin, translation, rotation and scale to the point).

Protected Member Functions

virtual void Render (RenderTarget &target, Renderer &renderer) const
 /see Drawable::Render
const Matrix3GetMatrix () const
 Get the transform matrix of the drawable.
const Matrix3GetInverseMatrix () 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 39 of file Sprite.cpp.

sf::Sprite::Sprite ( const Image image,
const Vector2f position = Vector2f(0, 0),
const Vector2f scale = Vector2f(1, 1),
float  rotation = 0.f,
const Color color = Color(255, 255, 255, 255) 
) [explicit]

Construct the sprite from a source image.

Parameters:
image : Image of the sprite
position : Position of the sprite
scale : Scale factor
rotation : Orientation, in degrees
color : Color of the sprite

Definition at line 51 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 117 of file Sprite.cpp.

void sf::Sprite::FlipY ( bool  flipped  ) 

Flip the sprite vertically.

Parameters:
flipped : True to flip the sprite

Definition at line 126 of file Sprite.cpp.

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

Get the current blending mode.

Returns:
Current blending mode

Definition at line 263 of file Drawable.cpp.

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

Get the color of the object.

Returns:
Current color

Definition at line 254 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 135 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 353 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 337 of file Drawable.cpp.

const Vector2f & sf::Drawable::GetOrigin (  )  const [inherited]

Get the local origin of the object.

Get the origin of the object.

Returns:
Current position of the origin

Definition at line 236 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).

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 163 of file Sprite.cpp.

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

Get the position of the object.

Returns:
Current position

Definition at line 218 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 245 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 227 of file Drawable.cpp.

Vector2f sf::Sprite::GetSize (  )  const

Get the sprite size.

Returns:
Size of the sprite

Definition at line 153 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 144 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 282 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 273 of file Drawable.cpp.

void sf::Sprite::Render ( RenderTarget target,
Renderer renderer 
) const [protected, virtual]

/see Drawable::Render

Implements sf::Drawable.

Definition at line 185 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 108 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 94 of file Sprite.cpp.

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

Rotate the object.

Parameters:
Angle : Angle of rotation, in degrees

Definition at line 309 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 300 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 291 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 209 of file Drawable.cpp.

void sf::Drawable::SetColor ( const Color color  )  [inherited]

Set the color of the object.

The default color is white

Parameters:
color : New color

The default color is white

Definition at line 199 of file Drawable.cpp.

void sf::Sprite::SetImage ( const Image image,
bool  adjustToNewSize = false 
)

Change the image of the sprite.

Set the image of the sprite.

Parameters:
image : New image
adjustToNewSize : If true, the SubRect of the sprite will be adjusted to the size of the new image

Definition at line 64 of file Sprite.cpp.

void sf::Drawable::SetOrigin ( const Vector2f origin  )  [inherited]

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

The default origin is (0, 0)

Parameters:
origin : New origin

The default origin is (0, 0)

Definition at line 175 of file Drawable.cpp.

void sf::Drawable::SetOrigin ( float  x,
float  y 
) [inherited]

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

The default origin is (0, 0)

Parameters:
x : X coordinate of the origin
y : Y coordinate of the origin

The default origin is (0, 0)

Definition at line 160 of file Drawable.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 74 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 64 of file Drawable.cpp.

void sf::Drawable::SetRotation ( float  angle  )  [inherited]

Set the orientation of the object.

Parameters:
angle : Angle of rotation, in degrees

Definition at line 184 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 118 of file Drawable.cpp.

void sf::Drawable::SetScale ( float  factorX,
float  factorY 
) [inherited]

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

Parameters:
factorX : New horizontal scale (must be strictly positive)
factorY : New vertical scale (must be strictly positive)

Definition at line 108 of file Drawable.cpp.

void sf::Drawable::SetScaleX ( float  factor  )  [inherited]

Set the X scale factor of the object.

Parameters:
factor : New X scale factor

Definition at line 128 of file Drawable.cpp.

void sf::Drawable::SetScaleY ( float  factor  )  [inherited]

Set the Y scale factor of the object.

Parameters:
factor : New Y scale factor

Definition at line 143 of file Drawable.cpp.

void sf::Sprite::SetSubRect ( const IntRect rectangle  ) 

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

By default, the subrect covers the entire source image

Parameters:
rectangle : New sub-rectangle

Definition at line 84 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 84 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.

Vector2f sf::Drawable::TransformToGlobal ( const Vector2f point  )  const [inherited]

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

Parameters:
point : Point to transform
Returns:
Transformed point

Definition at line 328 of file Drawable.cpp.

Vector2f sf::Drawable::TransformToLocal ( const Vector2f point  )  const [inherited]

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

Parameters:
point : Point to transform
Returns:
Transformed point

Definition at line 319 of file Drawable.cpp.


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