05_Object Visual Composition and Animation Structure
3 min read
Object Visual Composition and Animation Structure
Overview
This document explains the visual elements and animation structure of objects through CSpriteComponent and CVFXComponent. It covers how object’s visual elements operate consistently and flexibly by managing resources, ensuring animation independence via shallow copies, and controlling visual effects.
Resource Relationship of Objects and Visual Components
When multiple objects share the same animation, they are synchronized and executed simultaneously. To allow individual control, animations are shallow-copied, and textures are shared across components using std::shared_ptr.
Class Descriptions
1. CAnimationManager & CTextureManager Classes
Role:
CAnimationManager and CTextureManager are resource managers. Each handles animation and texture resources by loading and storing them by key, provides them upon request, and manages their lifetimes.
class CAnimation{ friend class CAnimationManager; friend class CSpriteComponent; friend class CVFXComponent;public: CAnimation(); ~CAnimation();protected: std::unordered_map<EAnimationState, std::shared_ptr<FAnimationData>> mAnimationStates; EAnimationState mCurrentState; // for EAnimationType::MOVE CTransform* mTransform; FVector2D mPrevPos; // for EAnimationType::MOVE & EAnimationType::TIME float mFrameInterval; int mCurrIdx; bool mLooped;private: void Update(float deltaTime); void Release(); CAnimation* Clone() const;public: const SDL_Rect& GetFrame(); bool IsPlayedOnce() const; void ResetPlayedOnce(); EAnimationState GetState() const; void SetState(EAnimationState state); void AddState(EAnimationState state, std::shared_ptr<FAnimationData> data);};
Role:
Manages animation states and frame data. EAnimationType::TIME switches frames based on elapsed time, while EAnimationType::MOVE switches frames based on movement distance.
Creates individual instances through shallow copying, allowing each object to play animations independently.
Plays the visual effect at the specified posonly if VFX is not playing.
Conclusion
By using the CSpriteComponent and CVFXComponent, the visual elements of objects can be managed efficiently and flexibly. The texture structure managed by std::shared_ptroptimizes resources, and animations cloned with shallow copies allow independent control per object.