Gamedev Framework (gf)  0.10.0
A C++14 framework for 2D games
Public Member Functions | List of all members
gf::BasicSprite Class Reference

#include <gf/BasicSprite.h>

Public Member Functions

 BasicSprite ()
 Default constructor. More...
 
 BasicSprite (const Texture &texture)
 Construct the sprite from a source texture. More...
 
 BasicSprite (const Texture &texture, const RectF &textureRect)
 Construct the sprite from a sub-rectangle of a source texture. More...
 
void setTexture (const Texture &texture, bool resetRect=false)
 Change the source texture of the sprite. More...
 
const TexturegetTexture () const
 Get the source texture of the sprite. More...
 
bool hasTexture () const
 Check if a texture is set. More...
 
void unsetTexture ()
 Unset the source texture of the sprite. More...
 
void setTextureRect (const RectF &rect)
 Set the sub-rectangle of the texture that the sprite will display. More...
 
const RectFgetTextureRect () const
 Get the sub-rectangle of the texture displayed by the sprite. More...
 
RectF getLocalBounds () const
 Get the local bounding rectangle of the entity. More...
 
void updateGeometry (BufferRef< Vertex > vertices)
 

Detailed Description

See also
gf::Sprite

Constructor & Destructor Documentation

◆ BasicSprite() [1/3]

gf::BasicSprite::BasicSprite ( )

Default constructor.

Creates an empty sprite with no source texture.

◆ BasicSprite() [2/3]

gf::BasicSprite::BasicSprite ( const Texture texture)

Construct the sprite from a source texture.

Parameters
textureSource texture
See also
setTexture()

◆ BasicSprite() [3/3]

gf::BasicSprite::BasicSprite ( const Texture texture,
const RectF textureRect 
)

Construct the sprite from a sub-rectangle of a source texture.

Parameters
textureSource texture
textureRectSub-rectangle of the texture to assign to the sprite
See also
setTexture(), setTextureRect()

Member Function Documentation

◆ getLocalBounds()

RectF gf::BasicSprite::getLocalBounds ( ) const

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.

Returns
Local bounding rectangle of the entity

◆ getTexture()

const Texture& gf::BasicSprite::getTexture ( ) const
inline

Get the source texture of the sprite.

The returned reference is const, which means that you can't modify the texture when you retrieve it with this function.

Returns
Reference to the sprite's texture
See also
setTexture()

◆ getTextureRect()

const RectF& gf::BasicSprite::getTextureRect ( ) const
inline

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

Returns
Texture rectangle of the sprite in texture coordinates
See also
setTextureRect()

◆ hasTexture()

bool gf::BasicSprite::hasTexture ( ) const
inline

Check if a texture is set.

Returns
True if a texture is already set
See also
setTexture(), getTexture()

◆ setTexture()

void gf::BasicSprite::setTexture ( const Texture texture,
bool  resetRect = false 
)

Change the source texture of the sprite.

The texture 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 behavior is undefined.

If resetRect is true, the texture rect 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
textureNew texture
resetRectShould the texture rect be reset to the size of the new texture?
See also
getTexture(), setTextureRect()

◆ setTextureRect()

void gf::BasicSprite::setTextureRect ( const RectF rect)

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

The rectangle is given in texture coordinates, meaning that \((0,0)\) is the top left corner and \((1,1)\) is the bottom right corner.

Parameters
rectRectangle defining the region of the texture to display
See also
getTextureRect(), setTexture()

◆ unsetTexture()

void gf::BasicSprite::unsetTexture ( )

Unset the source texture of the sprite.

After a call to this function, the sprite has no source texture.

See also
setTexture()

◆ updateGeometry()

void gf::BasicSprite::updateGeometry ( BufferRef< Vertex vertices)