dEngine
Simple 2D C++ game engine
SpriteSheet.h
Go to the documentation of this file.
1 #ifndef DENGINE_SPRITESHEET_H
2 #define DENGINE_SPRITESHEET_H
3 
4 #include <SDL.h>
5 #include <SDL_image.h>
6 #include "../System/Game.h"
7 #include "../System/Time.h"
8 #include "../System/Component.h"
9 
10 
11 namespace dengine {
18  class Animation {
19  public:
20  Animation() : rect({0, 0, 0, 0}), frames(1) {}
21 
22  Animation(SDL_Rect rect, int frames) : rect(rect), frames(frames) {}
23 
24  SDL_Rect rect;
25  int frames;
26  };
27 
33  class SpriteSheet : public Component {
34  public:
41  SpriteSheet(std::string filepath, GameObject &parent);
42 
47  ~SpriteSheet();
48 
54  void SetCurrentAnimation(std::string name);
55 
66  void RegisterAnimation(std::string name, int x, int y, int w, int h, int frames);
67 
73  void DeregisterAnimation(std::string name);
74 
81  bool HasAnimation(std::string name);
82 
86  void Render() override;
87 
91  void Pause(bool pause);
92 
93  private:
94  std::map <std::string, Animation> animationCollection;
95  SDL_Texture *sheet;
96  std::string currentAnimation = "";
97  bool isPaused = false;
98  };
99 }
100 #endif //DENGINE_SPRITESHEET_H
A base object for a game The gameobject can be considered the most basic building block of a game...
Definition: GameObject.h:19
SDL_Texture * sheet
Definition: SpriteSheet.h:95
Animation from a spritesheet.
Definition: SpriteSheet.h:18
std::map< std::string, Animation > animationCollection
Definition: SpriteSheet.h:94
Pause Screen.
Definition: GameStates.h:17
SDL_Rect rect
Definition: SpriteSheet.h:24
Animation()
Definition: SpriteSheet.h:20
Gameobject component that asssists in adding additional functionality.
Definition: Component.h:14
Animation(SDL_Rect rect, int frames)
Definition: SpriteSheet.h:22
A SpriteSheet.
Definition: SpriteSheet.h:33
The namespace containing the engine&#39;s code.
Definition: Collider.h:9
int frames
Definition: SpriteSheet.h:25