Sprite

Drawable representation of a texture, with its own transformations, color, etc.

Sprite is a drawable class that allows to easily display a texture (or a part of it) on a render target.

It inherits all the functions from Transformable: position, rotation, scale, origin. It also adds sprite-specific properties such as the texture to use, the part of it to display, and some convenience functions to change the overall color of the sprite, or to get its bounding rectangle.

Sprite works in combination with the Texture class, which loads and provides the pixel data of a given texture.

The separation of Sprite and Texture allows more flexibility and better performances: indeed a Texture is a heavy resource, and any operation on it is slow (often too slow for real-time applications). On the other side, a Sprite is a lightweight object which can use the pixel data of a Texture and draw it with its own transformation/color/blending attributes.

It is important to note that the Sprite instance doesn't copy the texture that it uses, it only keeps a reference to it. Thus, a Texture must not be destroyed while it is used by a Sprite (i.e. never write a function that uses a local Texture instance for creating a sprite).

Constructors

this
this()
Undocumented in source.
this
this(const(Texture) texture)
Undocumented in source.

Destructor

~this
~this()
Undocumented in source.

Members

Functions

draw
void draw(RenderTarget renderTarget, RenderStates renderStates)

Draw the sprite to a render target.

getGlobalBounds
FloatRect getGlobalBounds()

Get the global bounding rectangle of the entity.

getLocalBounds
FloatRect getLocalBounds()

Get the local bounding rectangle of the entity.

getTexture
const(Texture) getTexture()

Get the source texture of the sprite.

setTexture
void setTexture(const(Texture) texture, bool rectReset)

Change the source texture of the shape.

updatePositions
void updatePositions()
Undocumented in source. Be warned that the author may not have intended to support it.
updateTexCoords
void updateTexCoords()
Undocumented in source. Be warned that the author may not have intended to support it.

Mixins

__anonymous
mixin NormalTransformable
Undocumented in source.

Properties

color
Color color [@property setter]

The global color of the sprite.

color
Color color [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
dup
Sprite dup [@property getter]

Create a new Sprite with the same data. Note that the texture is not copied, only its reference.

textureRect
IntRect textureRect [@property setter]

The sub-rectangle of the texture that the sprite will display.

textureRect
IntRect textureRect [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.

Mixed In Members

From mixin NormalTransformable

origin
Vector2f origin [@property setter]

The local origin of the object.

origin
Vector2f origin [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
position
Vector2f position [@property setter]

The position of the object. The default is (0, 0).

position
Vector2f position [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
rotation
float rotation [@property setter]

The orientation of the object, in degrees. The default is 0 degrees.

rotation
float rotation [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
scale
Vector2f scale [@property setter]

The scale factors of the object. The default is (1, 1).

scale
Vector2f scale [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
getInverseTransform
const(Transform) getInverseTransform()

Get the inverse of the combined transform of the object.

getTransform
const(Transform) getTransform()

Get the combined transform of the object.

move
void move(Vector2f offset)

Move the object by a given offset.

Inherited Members

From Drawable

draw
void draw(RenderTarget renderTarget, RenderStates renderStates)

Draw the object to a render target.

From Transformable

origin
Vector2f origin [@property setter]

The local origin of the object.

origin
Vector2f origin [@property getter]
Undocumented in source.
position
Vector2f position [@property setter]

The position of the object. The default is (0, 0).

position
Vector2f position [@property getter]
Undocumented in source.
rotation
float rotation [@property setter]

The orientation of the object, in degrees. The default is 0 degrees.

rotation
float rotation [@property getter]
Undocumented in source.
scale
Vector2f scale [@property setter]

The scale factors of the object. The default is (1, 1).

scale
Vector2f scale [@property getter]
Undocumented in source.
getTransform
const(Transform) getTransform()

Get the inverse of the combined transform of the object.

getInverseTransform
const(Transform) getInverseTransform()

Get the combined transform of the object.

move
void move(Vector2f offset)

Move the object by a given offset.

See Also

Meta

Authors

Laurent Gomila, Jeremy DeHaan