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

Spritesheet takes all the functionality of SpriteBase, generates animation data for the texture, and expects it to be used manually. More...

#include <Spritesheet.h>

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

Public Member Functions

 Spritesheet (IAnimationFactory *animationFactory, AbstractTextureFactory *textureFactory, const std::string &animationPath, const int &startingFrame)
 Constructs the spritesheet with the default SpriteBase constructor, internally calling LoadTexture.
void SetFrame (const int &frameIndex)
 Sets the current frame for the animation.
int GetFrame () const
 Gets the current frame index.
Public Member Functions inherited from Mochi::Graphics::SpriteBase
 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< AnimationsDatamAnimationsData
Protected Attributes inherited from Mochi::Graphics::SpriteBase
std::shared_ptr< ITexturemTexture
Rectf mSrcRect
uint16_t mZindex
bool mVisible
uint8_t mAlpha
Vector2f mSize
std::shared_ptr< TransformmTransform

Detailed Description

Spritesheet takes all the functionality of SpriteBase, generates animation data for the texture, and expects it to be used manually.

This means that the Spritesheet generates a texture containing several sprites, and the user is responsible to change frames.

This has several uses. If a sprite has animations that are not represented with traditional flows (forward, backward, pingpong) this allows to change the frames manually. It also works to create sprite atlases and improve performance, using the same texture for a lot of different sprites.

Ownership:

  • It has shared ownership of the animation data with the animation factory.

Guarantees:

  • If animation file is valid, the sprite will at least have a frame and start on the selected frame, with a source rect according the data.

Not responsible:

  • This class does not animate, but changing the frame index over time animates the sprite. Check AnimatedSprite.h for this purpose.

Constructor & Destructor Documentation

◆ Spritesheet()

Mochi::Graphics::Spritesheet::Spritesheet ( IAnimationFactory * animationFactory,
AbstractTextureFactory * textureFactory,
const std::string & animationPath,
const int & startingFrame )

Constructs the spritesheet with the default SpriteBase constructor, internally calling LoadTexture.

Parameters
animationFactoryThe animation factory.
textureFactoryThe texture factory.
animationPathThe path or unique identifier to the animation file in the file system.
startingFrameThe first frame the sprite will show.

Member Function Documentation

◆ GetFrame()

int Mochi::Graphics::Spritesheet::GetFrame ( ) const

Gets the current frame index.

Returns
Current frame index

◆ SetFrame()

void Mochi::Graphics::Spritesheet::SetFrame ( const int & frameIndex)

Sets the current frame for the animation.

Parameters
frameIndexA 0 based index of which texture is going to be shown.

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