Platformer
Platformer
AnimationRenderComponent.hpp
1 #ifndef ANIMATION_RENDER_COMPONENT_HPP
2 #define ANIMATION_RENDER_COMPONENT_HPP
3 
4 #include <unordered_map>
5 #include <vector>
6 
7 #include "FilePaths.hpp"
8 #include "RenderComponent.hpp"
9 
11 struct Animation {
13  std::string spriteSheet;
14 
16  unsigned int srcX;
18  unsigned int srcY;
20  unsigned int srcW;
22  unsigned int srcH;
23 
25  unsigned int numFrames;
26 
28  unsigned int frameDifference;
29 
31  unsigned int FPS;
32 
34  Animation(
35  const std::string& spriteSheet,
37  unsigned int srcX,
39  unsigned int srcY,
41  unsigned int srcW,
43  unsigned int srcH,
45  unsigned int numFrames,
47  unsigned int frameDifference,
49  unsigned int FPS);
50 
52  std::shared_ptr<SDL_Rect> GetRectForFrame(
53  unsigned int frame);
54 };
55 
61  public:
64  std::unordered_map<unsigned int, Animation> map);
65 
67  void SwitchState(
68  unsigned int state);
69 
70  void Update() override;
71 
72  private:
74  std::unordered_map<unsigned int, Animation> stateMap;
75 
77  unsigned int curState;
78 
80  unsigned int curIndex;
81 
83  float timer;
84 };
85 
86 #endif
std::shared_ptr< SDL_Rect > GetRectForFrame(unsigned int frame)
Gets the rect of the spritesheet representing the current frame.
Definition: AnimationRenderComponent.cpp:19
unsigned int srcY
The source rect&#39;s y coordinate for this animation.
Definition: AnimationRenderComponent.hpp:18
A RenderComponent class.
Definition: RenderComponent.hpp:13
unsigned int FPS
The frames per second of this animation.
Definition: AnimationRenderComponent.hpp:31
void SwitchState(unsigned int state)
Switches the current animation state.
Definition: AnimationRenderComponent.cpp:37
unsigned int srcX
The source rect&#39;s x coordinate for this animation.
Definition: AnimationRenderComponent.hpp:16
std::string spriteSheet
The spritesheet for this animation.
Definition: AnimationRenderComponent.hpp:13
unsigned int srcW
The source rect&#39;s width for this animation.
Definition: AnimationRenderComponent.hpp:20
unsigned int numFrames
The number of frames of this animation.
Definition: AnimationRenderComponent.hpp:25
unsigned int srcH
The source rect&#39;s height for this animation.
Definition: AnimationRenderComponent.hpp:22
std::unordered_map< unsigned int, Animation > stateMap
The map of state IDs to animations.
Definition: AnimationRenderComponent.hpp:74
unsigned int curIndex
The current frame of the animation.
Definition: AnimationRenderComponent.hpp:80
AnimationRenderComponent(std::unordered_map< unsigned int, Animation > map)
Constructs a new AnimationRenderComponent.
Definition: AnimationRenderComponent.cpp:31
Animation(const std::string &spriteSheet, unsigned int srcX, unsigned int srcY, unsigned int srcW, unsigned int srcH, unsigned int numFrames, unsigned int frameDifference, unsigned int FPS)
Constructs a new animation.
Definition: AnimationRenderComponent.cpp:6
An AnimationRenderComponent class.
Definition: AnimationRenderComponent.hpp:60
Struct for a single animation.
Definition: AnimationRenderComponent.hpp:11
unsigned int curState
The current state of this animation eg: running.
Definition: AnimationRenderComponent.hpp:77
float timer
Times when the next frame of the animation is needed.
Definition: AnimationRenderComponent.hpp:83
void Update() override
Updates this component.
Definition: AnimationRenderComponent.cpp:48
unsigned int frameDifference
The x-axis distance between each frame of the animation.
Definition: AnimationRenderComponent.hpp:28