MochiEngine
Loading...
Searching...
No Matches
Mochi::Graphics::SpriteBase Class Reference

This class contains all the necessary data to show textures on screen. More...

#include <SpriteBase.h>

Inheritance diagram for Mochi::Graphics::SpriteBase:
Mochi::Graphics::Spritesheet Mochi::Graphics::AnimatedSprite Mochi::Graphics::OneshotAnimation

Public Member Functions

 SpriteBase (AbstractTextureFactory *factory, const std::string &path)
 Constructor that internally calls LoadTexture(AbstractTextureFactory *textureFactory, const std::string &filename).
 SpriteBase ()
 This constructor only initializes a minimal part of the sprite. LoadTexture(AbstractTextureFactory *textureFactory, const std::string &filename) needs to be called for the sprite to be valid.
void LoadTexture (AbstractTextureFactory *textureFactory, const std::string &path)
 Loads the texture and caches its size for future rendering.
virtual std::vector< RenderCommandGetRenderData () const
 Gets the list of render commands that represent this sprite in a format compatible with the renderer.
virtual void Update (const float &dt)
 Overridable api to work with animated sprites.
void SetZIndex (const uint16_t &zIndex)
uint16_t GetZIndex () const
bool IsVisible () const
void SetVisible (const bool &visible)
uint8_t GetAlpha () const
void SetAlpha (const uint8_t &alpha)
std::shared_ptr< TransformGetTransform () const
void SetTransform (std::shared_ptr< Transform > tr)
void SetSrcRect (const Rectf &src)

Protected Attributes

std::shared_ptr< ITexturemTexture
Rectf mSrcRect
uint16_t mZindex
bool mVisible
uint8_t mAlpha
Vector2f mSize
std::shared_ptr< TransformmTransform

Detailed Description

This class contains all the necessary data to show textures on screen.

Ownership:

  • The texture is shared between the sprite and the texture factory (and probably other sprites with the same texture identifier)
  • The transform is initialized in this class, but is shared and can be obtained and reused on other places, like colliders or debug gizmos.

Guarantees:

  • The render data obtained is always up to date with the texture and transform.
  • The texture has its color modified by the alpha value in the class.
  • It won't be shown if invisible.
  • Texture and transform will exist as long as the sprite exist (unless manually deleted somewhere).

Not responsible:

  • Sending its data to the renderer (user is responsible to send the RenderCommand to the renderer).

Constructor & Destructor Documentation

◆ SpriteBase()

Mochi::Graphics::SpriteBase::SpriteBase ( AbstractTextureFactory * factory,
const std::string & path )

Constructor that internally calls LoadTexture(AbstractTextureFactory *textureFactory, const std::string &filename).

Parameters
factoryThe texture factory from which to get the texture.
pathThe path or unique identifier of the file in the file system.

Member Function Documentation

◆ GetRenderData()

std::vector< RenderCommand > Mochi::Graphics::SpriteBase::GetRenderData ( ) const
virtual

Gets the list of render commands that represent this sprite in a format compatible with the renderer.

Returns
The list of render commands.

◆ LoadTexture()

void Mochi::Graphics::SpriteBase::LoadTexture ( AbstractTextureFactory * textureFactory,
const std::string & path )

Loads the texture and caches its size for future rendering.

Parameters
textureFactoryThe texture factory from which to get the texture.
pathThe path or unique identifier of the file in the file system.

◆ Update()

void Mochi::Graphics::SpriteBase::Update ( const float & dt)
virtual

Overridable api to work with animated sprites.

Parameters
dtThe delta time

Reimplemented in Mochi::Graphics::AnimatedSprite, and Mochi::Graphics::OneshotAnimation.


The documentation for this class was generated from the following files:
  • Engine/src/Graphics/SpriteBase.h
  • Engine/src/Graphics/SpriteBase.cpp