Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::Sprite Class Reference

Graphics class that represents the rendering of a sprite. More...

Inheritance diagram for Nz::Sprite:
Nz::InstancedRenderable Nz::RefCounted

Public Member Functions

 Sprite ()
 Constructs a Sprite object by default.
 
 Sprite (MaterialRef material)
 Constructs a Sprite object with a reference to a material. More...
 
 Sprite (Texture *texture)
 Constructs a Sprite object with a pointer to a texture. More...
 
 Sprite (const Sprite &sprite)
 Constructs a Sprite object by assignation. More...
 
 Sprite (Sprite &&)=delete
 
void AddToRenderQueue (AbstractRenderQueue *renderQueue, const InstanceData &instanceData) const override
 Adds the sprite to the rendering queue. More...
 
const ColorGetColor () const
 Gets the color of the sprite. More...
 
const ColorGetCornerColor (RectCorner corner) const
 Gets the color setup on a corner of the sprite. More...
 
const Vector3fGetOrigin () const
 Gets the origin of the sprite. More...
 
const Vector2fGetSize () const
 Gets the size of the sprite. More...
 
const RectfGetTextureCoords () const
 Gets the texture coordinates of the sprite. More...
 
void SetColor (const Color &color)
 Sets the global color of the sprite. More...
 
void SetCornerColor (RectCorner corner, const Color &color)
 Sets a color for a corner of the sprite. More...
 
void SetDefaultMaterial ()
 Sets the default material of the sprite (just default material)
 
void SetMaterial (MaterialRef material, bool resizeSprite=true)
 Changes the material of the sprite. More...
 
bool SetMaterial (String materialName, bool resizeSprite=true)
 Sets the material of the sprite from a name. More...
 
void SetMaterial (std::size_t skinIndex, MaterialRef material, bool resizeSprite=true)
 Sets the material of the sprite. More...
 
bool SetMaterial (std::size_t skinIndex, String materialName, bool resizeSprite=true)
 Sets the material of the sprite from a name for a specific skin. More...
 
void SetOrigin (const Vector3f &origin)
 Sets the origin of the sprite. More...
 
void SetSize (const Vector2f &size)
 Sets the size of the sprite. More...
 
void SetSize (float sizeX, float sizeY)
 Sets the size of the sprite. More...
 
bool SetTexture (String textureName, bool resizeSprite=true)
 Sets the texture of the sprite from a name for the current skin. More...
 
void SetTexture (TextureRef texture, bool resizeSprite=true)
 Sets the texture of the sprite for the current skin. More...
 
bool SetTexture (std::size_t skinIndex, String textureName, bool resizeSprite=true)
 Sets the texture of the sprite from a name for a specific skin. More...
 
void SetTexture (std::size_t skinIndex, TextureRef texture, bool resizeSprite=true)
 Sets the texture of the sprite for a specific skin. More...
 
void SetTextureCoords (const Rectf &coords)
 Sets the texture coordinates of the sprite. More...
 
void SetTextureRect (const Rectui &rect)
 Sets the texture rectangle of the sprite. More...
 
Spriteoperator= (const Sprite &sprite)
 Sets the current sprite with the content of the other one. More...
 
Spriteoperator= (Sprite &&sprite)=delete
 
- Public Member Functions inherited from Nz::InstancedRenderable
 InstancedRenderable ()
 Constructs a InstancedRenderable object by default.
 
 InstancedRenderable (const InstancedRenderable &renderable)
 Constructs a InstancedRenderable object by assignation. More...
 
 InstancedRenderable (InstancedRenderable &&renderable)=delete
 
virtual ~InstancedRenderable ()
 Destructs the object and calls OnInstancedRenderableRelease. More...
 
virtual bool Cull (const Frustumf &frustum, const InstanceData &instanceData) const
 Culls the instanced if not in the frustum. More...
 
void EnsureBoundingVolumeUpdated () const
 Ensures that the bounding volume is up to date.
 
virtual const BoundingVolumefGetBoundingVolume () const
 Gets the bounding volume. More...
 
const MaterialRefGetMaterial (std::size_t matIndex=0) const
 Gets one of the material used by the object. More...
 
const MaterialRefGetMaterial (std::size_t skinIndex, std::size_t matIndex) const
 Gets one of the material used by the object, independently from the active skin. More...
 
std::size_t GetMaterialCount () const
 Gets the number of material per skin. More...
 
std::size_t GetSkin () const
 Gets the current active skin index. More...
 
std::size_t GetSkinCount () const
 Gets the number of skins this object has. More...
 
virtual void InvalidateData (InstanceData *instanceData, UInt32 flags) const
 Invalidates data for instanced. More...
 
void SetSkin (std::size_t skinIndex)
 Changes the active skin. More...
 
void SetSkinCount (std::size_t skinCount)
 Changes the maximum skin count of the object. More...
 
virtual void UpdateBoundingVolume (InstanceData *instanceData) const
 Updates the bounding volume. More...
 
InstancedRenderableoperator= (const InstancedRenderable &renderable)
 Sets the current instanced renderable with the content of the other one. More...
 
InstancedRenderableoperator= (InstancedRenderable &&renderable)=delete
 
 NazaraSignal (OnInstancedRenderableInvalidateBoundingVolume, const InstancedRenderable *)
 
 NazaraSignal (OnInstancedRenderableInvalidateData, const InstancedRenderable *, UInt32)
 
 NazaraSignal (OnInstancedRenderableInvalidateMaterial, const InstancedRenderable *, std::size_t, std::size_t, const MaterialRef &)
 
 NazaraSignal (OnInstancedRenderableRelease, const InstancedRenderable *)
 
 NazaraSignal (OnInstancedRenderableResetMaterials, const InstancedRenderable *, std::size_t)
 
 NazaraSignal (OnInstancedRenderableSkinChange, const InstancedRenderable *, std::size_t)
 
- Public Member Functions inherited from Nz::RefCounted
 RefCounted (bool persistent=true)
 Constructs a RefCounted object with a persistance aspect. More...
 
 RefCounted (const RefCounted &)=delete
 
 RefCounted (RefCounted &&)=default
 
virtual ~RefCounted ()
 Destructs the object. More...
 
void AddReference () const
 Adds a reference to the object.
 
unsigned int GetReferenceCount () const
 Gets the number of references to the object. More...
 
bool IsPersistent () const
 Checks whether the object is persistent. More...
 
bool RemoveReference () const
 Removes a reference to the object. More...
 
bool SetPersistent (bool persistent=true, bool checkReferenceCount=false)
 Sets the persistence of the object. More...
 
RefCountedoperator= (const RefCounted &)=delete
 
RefCountedoperator= (RefCounted &&)=default
 

Static Public Member Functions

template<typename... Args>
static SpriteRef New (Args &&... args)
 Creates a new sprite from the arguments. More...
 

Friends

class Graphics
 

Additional Inherited Members

- Protected Member Functions inherited from Nz::InstancedRenderable
void InvalidateBoundingVolume ()
 Invalidates the bounding volume.
 
void InvalidateInstanceData (UInt32 flags)
 Invalidates the instance data based on flags. More...
 
void ResetMaterials (std::size_t matCount, std::size_t skinCount=1)
 Resets the materials, material count and skin count. More...
 
void SetMaterial (std::size_t matIndex, MaterialRef material)
 Changes the material used at the specified index by another one. More...
 
void SetMaterial (std::size_t skinIndex, std::size_t matIndex, MaterialRef material)
 Changes the material used at the specified index by another one, independently from the active skin. More...
 
- Protected Attributes inherited from Nz::InstancedRenderable
BoundingVolumef m_boundingVolume
 

Detailed Description

Graphics class that represents the rendering of a sprite.

Constructor & Destructor Documentation

◆ Sprite() [1/3]

Nz::Sprite::Sprite ( MaterialRef  material)
inline

Constructs a Sprite object with a reference to a material.

Parameters
materialReference to a material

◆ Sprite() [2/3]

Nz::Sprite::Sprite ( Texture *  texture)
inline

Constructs a Sprite object with a pointer to a texture.

Parameters
texturePointer to a texture

◆ Sprite() [3/3]

Nz::Sprite::Sprite ( const Sprite sprite)
inline

Constructs a Sprite object by assignation.

Parameters
spriteSprite to copy into this

Member Function Documentation

◆ AddToRenderQueue()

void Nz::Sprite::AddToRenderQueue ( AbstractRenderQueue renderQueue,
const InstanceData &  instanceData 
) const
overridevirtual

Adds the sprite to the rendering queue.

Parameters
renderQueueQueue to be added
instanceDataData for the instance

Implements Nz::InstancedRenderable.

◆ GetColor()

const Color & Nz::Sprite::GetColor ( ) const
inline

Gets the color of the sprite.

This is the global color of the sprite, independent from corner colors

Returns
Current color
See also
GetCornerColor
SetColor

◆ GetCornerColor()

const Color & Nz::Sprite::GetCornerColor ( RectCorner  corner) const
inline

Gets the color setup on a corner of the sprite.

Returns
Current color
Parameters
cornerCorner of the sprite to query
See also
SetCornerColor

◆ GetOrigin()

const Vector3f & Nz::Sprite::GetOrigin ( ) const
inline

Gets the origin of the sprite.

Returns
Current material
See also
SetOrigin

◆ GetSize()

const Vector2f & Nz::Sprite::GetSize ( ) const
inline

Gets the size of the sprite.

Returns
Current size

◆ GetTextureCoords()

const Rectf & Nz::Sprite::GetTextureCoords ( ) const
inline

Gets the texture coordinates of the sprite.

Returns
Current texture coordinates

◆ New()

template<typename... Args>
SpriteRef Nz::Sprite::New ( Args &&...  args)
static

Creates a new sprite from the arguments.

Returns
A reference to the newly created sprite
Parameters
argsArguments for the sprite

◆ operator=()

Sprite & Nz::Sprite::operator= ( const Sprite sprite)
inline

Sets the current sprite with the content of the other one.

Returns
A reference to this
Parameters
spriteThe other Sprite

◆ SetColor()

void Nz::Sprite::SetColor ( const Color color)
inline

Sets the global color of the sprite.

This is independent from the corner color of the sprite

Parameters
colorColor for the sprite
See also
GetColor
SetCornerColor

◆ SetCornerColor()

void Nz::Sprite::SetCornerColor ( RectCorner  corner,
const Color color 
)
inline

Sets a color for a corner of the sprite.

This is independent from the sprite global color, which gets multiplied by the corner color when rendering the sprite.

Parameters
cornerCorner of the sprite to set
colorColor for the sprite
See also
GetCornerColor
SetColor

◆ SetMaterial() [1/4]

void Nz::Sprite::SetMaterial ( MaterialRef  material,
bool  resizeSprite = true 
)
inline

Changes the material of the sprite.

Parameters
materialMaterial for the sprite
resizeSpriteShould billboard be resized to the material size (diffuse map)

◆ SetMaterial() [2/4]

bool Nz::Sprite::SetMaterial ( String  materialName,
bool  resizeSprite = true 
)

Sets the material of the sprite from a name.

Tries to get a material from the MaterialLibrary and then the MaterialManager (which will treat the name as a path) Fails if the texture name is not a part of the MaterialLibrary nor the MaterialManager (which fails if it couldn't load the texture from its filepath)

Parameters
materialNameNamed texture for the material
resizeSpriteShould the sprite be resized to the material diffuse map size?
Returns
True if the material was found or loaded from its name/path, false if it couldn't

◆ SetMaterial() [3/4]

void Nz::Sprite::SetMaterial ( std::size_t  skinIndex,
MaterialRef  material,
bool  resizeSprite = true 
)
inline

Sets the material of the sprite.

Parameters
skinIndexSkin index to change
materialMaterial for the sprite
resizeBillboardShould billboard be resized to the material size (diffuse map)

◆ SetMaterial() [4/4]

bool Nz::Sprite::SetMaterial ( std::size_t  skinIndex,
String  materialName,
bool  resizeSprite = true 
)

Sets the material of the sprite from a name for a specific skin.

Tries to get a material from the MaterialLibrary and then the MaterialManager (which will treat the name as a path) Fails if the texture name is not a part of the MaterialLibrary nor the MaterialManager (which fails if it couldn't load the texture from its filepath)

Parameters
skinIndexSkin index to change
materialNameNamed texture for the material
resizeSpriteShould the sprite be resized to the material diffuse map size?
Returns
True if the material was found or loaded from its name/path, false if it couldn't

◆ SetOrigin()

void Nz::Sprite::SetOrigin ( const Vector3f origin)
inline

Sets the origin of the sprite.

The origin is the center of translation/rotation/scaling of the sprite.

Parameters
originNew origin for the sprite
See also
GetOrigin

◆ SetSize() [1/2]

void Nz::Sprite::SetSize ( const Vector2f size)
inline

Sets the size of the sprite.

Parameters
sizeSize for the sprite

◆ SetSize() [2/2]

void Nz::Sprite::SetSize ( float  sizeX,
float  sizeY 
)
inline

Sets the size of the sprite.

Parameters
sizeXSize in X for the sprite
sizeYSize in Y for the sprite

◆ SetTexture() [1/4]

bool Nz::Sprite::SetTexture ( String  textureName,
bool  resizeSprite = true 
)

Sets the texture of the sprite from a name for the current skin.

Returns
True if the texture was found or loaded from its name/path, false if it couldn't

Tries to get a texture from the TextureLibrary and then the TextureManager (which will treat the name as a path) Fails if the texture name is not a part of the TextureLibrary nor the TextureManager (which fails if it couldn't load the texture from its filepath)

Parameters
textureNameNamed texture for the sprite
resizeSpriteShould the sprite be resized to the texture size?
Remarks
The sprite material gets copied to prevent accidentally changing other drawable materials

◆ SetTexture() [2/4]

void Nz::Sprite::SetTexture ( TextureRef  texture,
bool  resizeSprite = true 
)
inline

Sets the texture of the sprite for the current skin.

This function changes the diffuse map of the material associated with the current skin

Parameters
textureTexture for the sprite
resizeSpriteShould the sprite be resized to the texture size?
Remarks
The sprite material gets copied to prevent accidentally changing other drawable materials

◆ SetTexture() [3/4]

bool Nz::Sprite::SetTexture ( std::size_t  skinIndex,
String  textureName,
bool  resizeSprite = true 
)

Sets the texture of the sprite from a name for a specific skin.

Returns
True if the texture was found or loaded from its name/path, false if it couldn't

Tries to get a texture from the TextureLibrary and then the TextureManager (which will treat the name as a path) Fails if the texture name is not a part of the TextureLibrary nor the TextureManager (which fails if it couldn't load the texture from its filepath)

Parameters
skinIndexNamed texture for the sprite
textureNameNamed texture for the sprite
resizeSpriteShould the sprite be resized to the texture size?
Remarks
The sprite material gets copied to prevent accidentally changing other drawable materials

◆ SetTexture() [4/4]

void Nz::Sprite::SetTexture ( std::size_t  skinIndex,
TextureRef  texture,
bool  resizeSprite = true 
)
inline

Sets the texture of the sprite for a specific skin.

This function changes the diffuse map of the material associated with the specified skin

Parameters
skinIndexSkin index to change
textureTexture for the sprite
resizeSpriteShould the sprite be resized to the texture size?
Remarks
The sprite material gets copied to prevent accidentally changing other drawable materials

◆ SetTextureCoords()

void Nz::Sprite::SetTextureCoords ( const Rectf coords)
inline

Sets the texture coordinates of the sprite.

Parameters
coordsTexture coordinates

◆ SetTextureRect()

void Nz::Sprite::SetTextureRect ( const Rectui rect)
inline

Sets the texture rectangle of the sprite.

Parameters
rectRectangles symbolizing the size of the texture
Remarks
Produces a NazaraAssert if material is invalid
Produces a NazaraAssert if material has no diffuse map

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