/********************************************************************
*
* File: fsCAnimatingSpriteComponent.h
*
* Purpose: A component which renders and animated sprite to the
* display.
*
*********************************************************************/
#ifndef fsCAnimatingSpriteComponenthdr
#define fsCAnimatingSpriteComponenthdr
#include<memory>
#include <fsCore/src/fsCUniqueId.h>
#include "fsIRenderableComponent.h"
class fsIAnimatingSprite;
class fsIAnimationData;
class fsCResourceName;
class fsCSprite;
class fsCAnimatingSpriteComponent : public fsIRenderableComponent
{
friend class fsCComponentFactory;
public:
static const fsCUniqueId mTypeId;
static const fsStr mEntityPrefix;
fsS32 heightGet() const;
void animationPlay(const fsStr& pAnimation);
// Per-instance playback controls. The start offset is re-applied whenever a
// new clip is played, allowing otherwise identical sprites to remain out of
// phase without changing their authored animation data.
void animationSpeedSet(fsF32 pSpeed);
void animationStartOffsetSet(fsS32 pOffsetMs);
fsBool animatingGet() const;
void stop();
void initialise(const fsStr& pFolderName, fsBool pHitMap);
void animationDataSet(const fsCResourceName& pAnimationFilename, fsBool pHitmap);
protected:
static fsIComponent* create(fsCEntity* pParent);
void initialiseFromVariableTableDo(const fsCVariableTable& pVars) override;
void deserialiseDo() override;
void updateDo(fsS32 pDeltaMs) override;
void renderDo() override;
void matrixApplyDo() override;
void resetDo() override;
fsCAnimatingSpriteComponent(fsCEntity* pParent);
virtual ~fsCAnimatingSpriteComponent();<--- Destructor in derived class
private:
fsCResourceName anmPrefixPlayfirstFilenameGet(const fsStr& pFolderName) const;
fsCResourceName anmPrefixSpriterFilenameGet(const fsStr& pFolderName) const;
fsCResourceName pureFilenameGet(const fsStr& pFolderName) const;
fsCResourceName fullFilenameGet(const fsStr& pFolderName) const;
void visiblityStateChangeHandlePostDeserialise();
void visiblityStateChangeHandle();
std::shared_ptr<fsIAnimatingSprite> mAnimatingSprite;
std::shared_ptr<fsCSprite> mAnimationRootSprt;
fsF32 mAnimationSpeed;
fsF32 mAnimationRemainderMs;
fsS32 mAnimationStartOffsetMs;
};
#endif