VEGO-Engine  0.1
Loading...
Searching...
No Matches
SpriteComponent.h
1#pragma once
2
3#include <map>
4#include <SDL3/SDL_render.h>
5#include <memory>
6#include <string>
7
8#include "Textures.h"
9#include "AnimationHandler.h"
10#include "Component.h"
11#include "Direction.h"
12#include "RenderObject.h"
13
15
16class SpriteComponent : public Component, public RenderObject
17{
18public:
19 int animationIndex = 0;
20
21 std::map<std::string, std::unique_ptr<Animation>>* animations = nullptr;
22
23private:
24 TransformComponent* transform;
25 SDL_Texture* texture;
26 SDL_FRect srcRect, destRect;
27
28 Textures textureEnum;
29
30 bool animated = false;
31 uint8_t frames = 0;
32 uint8_t speed = 100;
33 bool flipped = false;
34
35 int textureXOffset;
36 int textureYOffset;
37
38 //there should be a better solution as this variable is only used for the loading of the tmx map
39 //TODO: improve this in the future and also remove it from the scope of the developer
40 const char* path;
41
42public:
43 //debug
44 Textures getTexture() { return this->textureEnum; }
45
46
47
48 SpriteComponent(Textures texture, int zIndex);
49 SpriteComponent(Textures texture, int xOffset, int yOffset, int zIndex);
50 SpriteComponent(const char* path, int xOffset, int yOffset, int zIndex);
51 SpriteComponent(
52 Textures texture,
53 bool isAnimated,
54 std::map<std::string, std::unique_ptr<Animation>>* animationList,
55 std::string defaultAnimation,
56 int zIndex);
57 ~SpriteComponent();
58
59 void setTexture(Textures texture);
60 void setMapTileTexture(const char* path);
61
62 void init() override;
63 void update(uint_fast16_t diffTime) override;
64 void draw() override;
65 void playAnimation(std::string type);
66 void setDirection(Direction direction);
67};
Definition Component.h:8
Forward declaration of the Textures enum class.
Definition TransformComponent.h:9