NWengine 0.9
Loading...
Searching...
No Matches
Sprite Class Reference

Represents a game sprite. More...

#include <Sprite.h>

Inheritance diagram for Sprite:
GameComponent Serialized

Public Member Functions

 Sprite ()=default
 Default constructor for the Sprite class.
 
 Sprite (GameObject *go)
 Constructor for the Sprite class.
 
 ~Sprite ()
 Destructor for the Sprite class.
 
void SetTexture (std::string path, bool alpha=1)
 Sets the texture of the sprite from a file path.
 
void SetTexture (const Image *image, TextureIdentifierPtr texId)
 Sets the texture of the sprite from an Image object.
 
void SetTexture (Texture *tex)
 Sets the texture of the sprite.
 
void SetShader (std::string path)
 Sets the shader of the sprite from a file path.
 
void SetShader (const ShaderText &st, ShaderIdentifier *id)
 Sets the shader of the sprite from a ShaderText object.
 
void SetShader (Shader *shader)
 Sets the shader of the sprite.
 
void SetSortingLayer (int order)
 Sets the sorting layer of the sprite.
 
void Render ()
 Renders the sprite.
 
void StopRendering ()
 Stops rendering the sprite.
 
void Batch (BatchType type=BatchType::DYNAMIC_BATCH)
 Batches the sprite.
 
void UnBatch ()
 Unbatches the sprite.
 
void Update () override
 Updates the sprite.
 
int Serialize (std::fstream *data, int offset) override
 Serializes the sprite data.
 
int Deserialize (std::fstream *data, int offset) override
 Deserializes the sprite data.
 
void SetGameObject (void *go) override
 Sets the GameObject that the sprite is attached to.
 
voidGetGameObject () override
 Gets the GameObject that the sprite is attached to.
 
- Public Member Functions inherited from GameComponent
virtual void Start ()
 Start the game component.
 
virtual ~GameComponent ()
 Destructor for the game component.
 
- Public Member Functions inherited from Serialized
 Serialized ()
 Default constructor for Serialized class.
 

Static Public Member Functions

static std::string GetType ()
 
static int DefaultSpriteDrawCallback (void *data)
 Default draw callback for sprites.
 
- Static Public Member Functions inherited from GameComponent
static std::string GetType ()
 Get the type of the game component.
 

Public Attributes

TextureIdentifier _texId {}
 
Texturetexture = nullptr
 
BatchType _isBatched = BatchType::UNBATCHED
 
int _lastSortingLayer = 0
 
bool _shouldDraw = 1
 
bool _isRendered = 1
 
fVec3 vertexAttributes
 
Shadershader = nullptr
 
Quad container
 
GameObjectattachedObj = nullptr
 
int sortingLayer = 0
 
double zbuffer = 1.0
 

Detailed Description

Represents a game sprite.

Represents a sprite component that can be attached to a game object.

Constructor & Destructor Documentation

◆ Sprite()

Sprite::Sprite ( GameObject * go)

Constructor for the Sprite class.

Parameters
goThe GameObject to attach the sprite to.

Member Function Documentation

◆ Batch()

void Sprite::Batch ( BatchType type = BatchType::DYNAMIC_BATCH)

Batches the sprite.

Parameters
typeThe batch type to use.

◆ DefaultSpriteDrawCallback()

int Sprite::DefaultSpriteDrawCallback ( void * data)
static

Default draw callback for sprites.

Parameters
dataThe data to pass to the draw callback.
Returns
The result of the draw callback.

◆ Deserialize()

int Sprite::Deserialize ( std::fstream * data,
int offset )
overridevirtual

Deserializes the sprite data.

Parameters
dataThe file stream to read the data from.
offsetThe offset in the file stream.
Returns
The number of bytes read.

Reimplemented from Serialized.

◆ GetGameObject()

void * Sprite::GetGameObject ( )
overridevirtual

Gets the GameObject that the sprite is attached to.

Returns
The GameObject that the sprite is attached to.

Reimplemented from GameComponent.

◆ Serialize()

int Sprite::Serialize ( std::fstream * data,
int offset )
overridevirtual

Serializes the sprite data.

Parameters
dataThe file stream to write the data to.
offsetThe offset in the file stream.
Returns
The number of bytes written.

Reimplemented from Serialized.

◆ SetGameObject()

void Sprite::SetGameObject ( void * go)
overridevirtual

Sets the GameObject that the sprite is attached to.

Parameters
goThe GameObject to set.

Reimplemented from GameComponent.

◆ SetShader() [1/3]

void Sprite::SetShader ( const ShaderText & st,
ShaderIdentifier * id )

Sets the shader of the sprite from a ShaderText object.

Parameters
stThe ShaderText object representing the shader.
idThe identifier of the shader.

◆ SetShader() [2/3]

void Sprite::SetShader ( Shader * shader)

Sets the shader of the sprite.

Parameters
shaderThe shader to set.

◆ SetShader() [3/3]

void Sprite::SetShader ( std::string path)

Sets the shader of the sprite from a file path.

Parameters
pathThe file path of the shader.

◆ SetSortingLayer()

void Sprite::SetSortingLayer ( int order)

Sets the sorting layer of the sprite.

Parameters
orderThe sorting order of the sprite.

◆ SetTexture() [1/3]

void Sprite::SetTexture ( const Image * image,
TextureIdentifierPtr texId )

Sets the texture of the sprite from an Image object.

Parameters
imageThe Image object representing the texture.
texIdThe identifier of the texture.

◆ SetTexture() [2/3]

void Sprite::SetTexture ( std::string path,
bool alpha = 1 )

Sets the texture of the sprite from a file path.

Parameters
pathThe file path of the texture.
alphaFlag indicating whether the texture has an alpha channel.

◆ SetTexture() [3/3]

void Sprite::SetTexture ( Texture * tex)

Sets the texture of the sprite.

Parameters
texThe texture to set.

◆ Update()

void Sprite::Update ( )
overridevirtual

Updates the sprite.

Reimplemented from GameComponent.

Member Data Documentation

◆ container

Quad Sprite::container

Container of the sprite

◆ sortingLayer

int Sprite::sortingLayer = 0

Sorting layer of the sprite

◆ vertexAttributes

fVec3 Sprite::vertexAttributes

Vertex attributes of the sprite

◆ zbuffer

double Sprite::zbuffer = 1.0

Z-buffer value of the sprite


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