The Table Engine
texture.h
Go to the documentation of this file.
1 #pragma once
2 
8 #include "SDL2/SDL.h"
9 #include "component.h"
10 #include "transform.h"
11 
20 class Texture : public Component {
21 protected:
22  SDL_Texture* m_texture;
23  SDL_Renderer* m_renderer;
24  SDL_Rect* m_spriteBox;
25  SDL_Rect* m_spriteClip;
26 
27  bool m_flipHorizontal = false;
28  bool m_flipVertical = false;
29  float m_angle = 0.0f;
30 
31 public:
35  Texture();
36 
41  Texture(SDL_Texture* texture);
42 
47  SDL_Texture* getTexture();
48 
53  virtual void setTexture(SDL_Texture* texture);
54 
60  virtual void setSizeInSpriteMap(int w, int h);
61 
67  virtual void setPositionInSpriteMap(int x, int y);
68 
73  virtual void setFlipHorizontal(bool flip);
74 
79  virtual void setFlipVertical(bool flip);
80 
85  virtual void setAngle(float angle);
86 
90  virtual void update() override;
91 
95  virtual void render() override;
96 
101  void setColorMod(const SDL_Color& color);
102 };
Base class for all game components, providing basic component functionalities.
Definition: component.h:25
Component for handling textures in the game engine.
Definition: texture.h:20
virtual void update() override
Updates texture properties, used mainly for animations or transformations.
Definition: texture.cpp:55
bool m_flipHorizontal
Flag for horizontal flipping of the texture.
Definition: texture.h:27
virtual void setTexture(SDL_Texture *texture)
Sets the SDL_Texture object.
Definition: texture.cpp:21
float m_angle
Rotation angle of the texture in degrees.
Definition: texture.h:29
SDL_Rect * m_spriteClip
Source rectangle in the sprite sheet for slicing the texture.
Definition: texture.h:25
virtual void setAngle(float angle)
Sets the rotation angle of the texture.
Definition: texture.cpp:51
virtual void setPositionInSpriteMap(int x, int y)
Sets the position of the sprite in the sprite map.
Definition: texture.cpp:37
SDL_Texture * m_texture
Pointer to the SDL_Texture object.
Definition: texture.h:22
Texture()
Default constructor for the Texture class, initializes an empty texture.
Definition: texture.cpp:5
virtual void setFlipHorizontal(bool flip)
Sets horizontal flip status.
Definition: texture.cpp:43
SDL_Texture * getTexture()
Retrieves the SDL_Texture object.
Definition: texture.cpp:17
void setColorMod(const SDL_Color &color)
Sets the color modulation for the texture.
Definition: texture.cpp:71
virtual void render() override
Renders the texture to the screen based on current properties.
Definition: texture.cpp:59
SDL_Rect * m_spriteBox
Destination rectangle on the screen for rendering the texture.
Definition: texture.h:24
virtual void setFlipVertical(bool flip)
Sets vertical flip status.
Definition: texture.cpp:47
bool m_flipVertical
Flag for vertical flipping of the texture.
Definition: texture.h:28
SDL_Renderer * m_renderer
Pointer to the SDL_Renderer associated with this texture.
Definition: texture.h:23
virtual void setSizeInSpriteMap(int w, int h)
Sets the size of the sprite in the sprite map.
Definition: texture.cpp:31
Defines the Component base class for all components in the game engine.
Provides the Transform component for positioning and sizing game objects.