My Project
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SpriteComponent Struct Reference

The SpriteComponent is responsible for rendering sprites on the screen. More...

#include <SpriteComponent.h>

Inheritance diagram for SpriteComponent:
Component

Public Member Functions

 SpriteComponent (SDL_Renderer *renderer, const char *filepath)
 Constructs a SpriteComponent with a renderer and a file path to the sprite's texture.
 
virtual ~SpriteComponent ()
 Destructor for SpriteComponent.
 
void CreateSprite (const char *filepath)
 Loads the sprite's texture from a file.
 
void Render (SDL_Renderer *renderer) override
 Renders the sprite on the screen.
 
void SetW (float w)
 Sets the sprite's width.
 
void SetX (float x)
 Sets the sprite's X position.
 
void SetY (float y)
 Sets the sprite's Y position.
 
float GetX () const
 Gets the sprite's X position.
 
float GetY () const
 Gets the sprite's Y position.
 
void Move (float x, float y)
 Moves the sprite to a new position.
 
SDL_FRect GetRectangle () const
 Gets the rectangle representing the sprite's position and size.
 
void SetSize (float w, float h)
 Sets the size of the sprite.
 
float GetWidth () const
 Gets the sprite's width.
 
float GetHeight () const
 Gets the sprite's height.
 
- Public Member Functions inherited from Component
virtual void Update (float deltaTime)
 

Detailed Description

The SpriteComponent is responsible for rendering sprites on the screen.

Inherits from Component and manages a texture for the sprite, including its position, size, and rendering.

Constructor & Destructor Documentation

◆ SpriteComponent()

SpriteComponent::SpriteComponent ( SDL_Renderer * renderer,
const char * filepath )
inline

Constructs a SpriteComponent with a renderer and a file path to the sprite's texture.

Parameters
rendererThe SDL renderer to use for rendering the sprite.
filepathThe file path to the texture image.

This constructor initializes the sprite component by loading the texture from the specified file path.

Member Function Documentation

◆ CreateSprite()

void SpriteComponent::CreateSprite ( const char * filepath)
inline

Loads the sprite's texture from a file.

Parameters
filepathThe file path to the texture image.

Attempts to load the sprite's texture using the ResourceManager. If the texture is not already loaded, it loads the texture and stores it in the ResourceManager.

◆ GetHeight()

float SpriteComponent::GetHeight ( ) const
inline

Gets the sprite's height.

Returns
The current height of the sprite.

◆ GetRectangle()

SDL_FRect SpriteComponent::GetRectangle ( ) const
inline

Gets the rectangle representing the sprite's position and size.

Returns
An SDL_FRect representing the sprite's position and size.

◆ GetWidth()

float SpriteComponent::GetWidth ( ) const
inline

Gets the sprite's width.

Returns
The current width of the sprite.

◆ GetX()

float SpriteComponent::GetX ( ) const
inline

Gets the sprite's X position.

Returns
The current X position of the sprite.

◆ GetY()

float SpriteComponent::GetY ( ) const
inline

Gets the sprite's Y position.

Returns
The current Y position of the sprite.

◆ Move()

void SpriteComponent::Move ( float x,
float y )
inline

Moves the sprite to a new position.

Parameters
xThe new X position of the sprite.
yThe new Y position of the sprite.

Updates the sprite's position to the specified X and Y coordinates.

◆ Render()

void SpriteComponent::Render ( SDL_Renderer * renderer)
inlineoverridevirtual

Renders the sprite on the screen.

Parameters
rendererThe SDL renderer to use for rendering the sprite.

If the sprite's texture is loaded, this method renders the sprite at its current position and size.

Reimplemented from Component.

◆ SetSize()

void SpriteComponent::SetSize ( float w,
float h )
inline

Sets the size of the sprite.

Parameters
wThe width of the sprite.
hThe height of the sprite.

Updates the sprite's width and height to the specified values.

◆ SetW()

void SpriteComponent::SetW ( float w)
inline

Sets the sprite's width.

Parameters
wThe new width of the sprite.

◆ SetX()

void SpriteComponent::SetX ( float x)
inline

Sets the sprite's X position.

Parameters
xThe new X position of the sprite.

◆ SetY()

void SpriteComponent::SetY ( float y)
inline

Sets the sprite's Y position.

Parameters
yThe new Y position of the sprite.

The documentation for this struct was generated from the following file: