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
17class SpriteComponent : public Component, public RenderObject
18{
19public:
20 int animationIndex = 0;
21
22 std::map<std::string, std::unique_ptr<Animation>>* animations = nullptr;
23
24private:
25 TransformComponent* transform;
26 SDL_Texture* texture;
27 SDL_FRect srcRect, destRect;
28
29 Textures textureEnum;
30
31 bool animated = false;
32 uint8_t frames = 0;
33 uint8_t speed = 100;
34 bool flipped = false;
35
36 int textureXOffset;
37 int textureYOffset;
38
39 //there should be a better solution as this variable is only used for the loading of the tmx map
40 //TODO: improve this in the future and also remove it from the scope of the developer
41 const char* path;
42
43public:
44 //debug
45 Textures getTexture() { return this->textureEnum; }
46
47
48
52 SpriteComponent(Textures texture, int zIndex);
53
58 SpriteComponent(Textures texture, int xOffset, int yOffset, int zIndex);
59
64 SpriteComponent(const char* path, int xOffset, int yOffset, int zIndex);
65
87 Textures texture,
88 bool isAnimated,
89 std::map<std::string, std::unique_ptr<Animation>>* animationList,
90 std::string defaultAnimation,
91 int zIndex,
92 int xOffset = 0,
93 int yOffset = 0);
94
96
97 void setTexture(Textures texture);
98 void setMapTileTexture(const char* path);
99
100 void init() override;
101 void update(uint_fast16_t diffTime) override;
102 void draw() override;
103
106 void playAnimation(std::string type);
107 void setDirection(Direction direction);
108};
void playAnimation(std::string type)
By name select which animation should be played (gets looped)
Definition SpriteComponent.cpp:101
SpriteComponent(Textures texture, int zIndex)
Constructor for SpriteComponent.
Definition SpriteComponent.cpp:18
Forward declaration of the Textures enum class.
The transform component is responsible for the position, direction and size of an entity....
Definition TransformComponent.h:10