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

OneshotAnimation is an AnimatedSprite limited to a single loop of an animation. It features a callback that is called when finishing that animation loop. This makes the class useful for oneshot effects like explosions, and allows to destroy or hide them after finishing. More...

#include <OneshotAnimation.h>

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

Public Member Functions

 OneshotAnimation (IAnimationFactory *, AbstractTextureFactory *, const std::string &animationPath, const std::string &mainAnimation)
virtual void Update (const float &dt) override
 This method updates an internal timer and changes frames when needed, according to the rules defined in the AnimationsData metadata. This needs to be called manually to work.
void SetFinishCallback (std::function< void()> onFinishedCallback)
Public Member Functions inherited from Mochi::Graphics::AnimatedSprite
 AnimatedSprite (IAnimationFactory *animationFactory, AbstractTextureFactory *textureFactory, const std::string &animationPath, const std::string &mainAnimation)
 Constructs the spritesheet with the default SpriteBase constructor, internally calling LoadTexture.
virtual void PlayAnimation (const std::string &animationName)
 Given an existing animation name, it starts that animation. This means immediately changing the frame, resetting the timer and setting the current animation.
void StopAnimation ()
 Stops the current animation and the timer, freezing the sprite in the current frame.
std::string GetCurrentAnimation () const
Public Member Functions inherited from 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.
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.
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)

Additional Inherited Members

Protected Attributes inherited from Mochi::Graphics::AnimatedSprite
bool mPlaying
float mTimer
int mLoops
bool mForward
std::string mCurrentAnimation
Protected Attributes inherited from Mochi::Graphics::Spritesheet
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

OneshotAnimation is an AnimatedSprite limited to a single loop of an animation. It features a callback that is called when finishing that animation loop. This makes the class useful for oneshot effects like explosions, and allows to destroy or hide them after finishing.

Ownership:

  • It owns the callback assigned with SetFinishCallback.

Guarantees:

  • The animation will be played once.
  • The callback will be invoked once, when the animation finishes.

Member Function Documentation

◆ Update()

void Mochi::Graphics::OneshotAnimation::Update ( const float & dt)
overridevirtual

This method updates an internal timer and changes frames when needed, according to the rules defined in the AnimationsData metadata. This needs to be called manually to work.

Parameters
dtThe delta time.

Reimplemented from Mochi::Graphics::AnimatedSprite.


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