Claire's Game Engine
Full C++ Engine using OpenGL
Loading...
Searching...
No Matches
SpriteRenderComponent Class Reference

SpriteRenderComponent is responsible for rendering textured 2D sprites. It operates in viewport space and is ideal for UI elements or 2D graphics. Supports draw ordering, flipping, and customizable rectangle dimensions. More...

#include <SpriteRenderComponent.h>

Inheritance diagram for SpriteRenderComponent:
RenderComponent Component AnimatedSpriteRenderComponent

Public Member Functions

 SpriteRenderComponent (Actor *pOwner, int pDrawOrder=100)
 Constructs a sprite render component without a texture.
 
 SpriteRenderComponent (Actor *pOwner, Texture *pTexture, int pDrawOrder=100)
 Constructs a sprite render component with an initial texture.
 
 SpriteRenderComponent ()=delete
 
 SpriteRenderComponent (const SpriteRenderComponent &)=delete
 
SpriteRenderComponentoperator= (const SpriteRenderComponent &)=delete
 
virtual void SetTexture (Texture *pTexture)
 Sets or updates the texture used by this sprite. Also updates internal texture dimensions.
 
virtual void Render (IRenderer *pRenderer) override
 Renders the sprite using the provided renderer. Applies flip settings and position based on the rectangle.
 
RenderType GetRenderType () override
 Returns the render type of this component (Viewport).
 
void SetNewDimensions (float x, float y)
 Sets new dimensions (width and height) for the sprite's rectangle.
 
void SetNewPositions (float x, float y)
 Sets a new position (x, y) for the sprite's rectangle.
 
int GetDrawOrder () const override
 Gets the drawing order priority of this component. Higher values render on top of lower values.
 
int GetTexWidth () const
 Gets the width of the texture used by this sprite.
 
int GetTexHeight () const
 Gets the height of the texture used by this sprite.
 
- Public Member Functions inherited from RenderComponent
 RenderComponent (Actor *pOwner)
 Constructs the RenderComponent and assigns it to the owning Actor.
 
void OnStart () override
 Called when the component is started. Registers the component with the scene's renderer for drawing.
 
void OnEnd () override
 Called when the component is removed or destroyed. Unregisters the component from the renderer.
 
- Public Member Functions inherited from Component
 Component (Actor *pOwner, int pUpdateOrder=100)
 Constructor for Component.
 
virtual ~Component ()
 
virtual void Update ()
 Called every frame to update the component. This can be used to perform actions that need to be updated periodically.
 
virtual void OnUpdateWorldTrandform ()
 Called when the world transform of the actor is updated. This allows the component to react to changes in the actor's world transform.
 
void SetActive (bool isActive)
 Sets the active status of the component.
 
void SetOwner (Actor *pOwner)
 Sets the actor that owns this component.
 
int GetUpdateOrder () const
 Returns the update order of the component. Components with lower update orders are updated first.
 
ActorGetOwner () const
 Returns the actor that owns this component.
 

Public Attributes

Rectangle mRectangle { Vector2(-16,-16),Vector2(32,32) }
 The rectangle defining sprite position and size, relative to the actor.
 
IRenderer::Flip mFlip = IRenderer::Flip::None
 Flip mode (none, horizontal, vertical, both) for sprite rendering.
 
- Public Attributes inherited from RenderComponent
Color mColor { 255,255,255,255 }
 

Protected Attributes

TexturemTexture
 The texture used for rendering this sprite.
 
int mDrawOrder
 Drawing order priority.
 
int mTexWidth
 Internal texture width (updated with SetTexture).
 
int mTexHeight
 Internal texture height (updated with SetTexture).
 
- Protected Attributes inherited from Component
ActormOwner = nullptr
 The actor that owns this component.
 

Detailed Description

SpriteRenderComponent is responsible for rendering textured 2D sprites. It operates in viewport space and is ideal for UI elements or 2D graphics. Supports draw ordering, flipping, and customizable rectangle dimensions.

Constructor & Destructor Documentation

◆ SpriteRenderComponent() [1/4]

SpriteRenderComponent::SpriteRenderComponent ( Actor * pOwner,
int pDrawOrder = 100 )

Constructs a sprite render component without a texture.

Parameters
pOwnerThe actor that owns this component.
pDrawOrderThe drawing order priority (higher values draw later).

◆ SpriteRenderComponent() [2/4]

SpriteRenderComponent::SpriteRenderComponent ( Actor * pOwner,
Texture * pTexture,
int pDrawOrder = 100 )

Constructs a sprite render component with an initial texture.

Parameters
pOwnerThe actor that owns this component.
pTextureThe texture to be rendered.
pDrawOrderThe drawing order priority.

◆ SpriteRenderComponent() [3/4]

SpriteRenderComponent::SpriteRenderComponent ( )
delete

◆ SpriteRenderComponent() [4/4]

SpriteRenderComponent::SpriteRenderComponent ( const SpriteRenderComponent & )
delete

Member Function Documentation

◆ GetDrawOrder()

int SpriteRenderComponent::GetDrawOrder ( ) const
overridevirtual

Gets the drawing order priority of this component. Higher values render on top of lower values.

Returns
Drawing order priority.

Reimplemented from RenderComponent.

◆ GetRenderType()

RenderType SpriteRenderComponent::GetRenderType ( )
overridevirtual

Returns the render type of this component (Viewport).

Returns
RenderType::Viewport

Implements RenderComponent.

◆ GetTexHeight()

int SpriteRenderComponent::GetTexHeight ( ) const

Gets the height of the texture used by this sprite.

Returns
Texture height in pixels.

◆ GetTexWidth()

int SpriteRenderComponent::GetTexWidth ( ) const

Gets the width of the texture used by this sprite.

Returns
Texture width in pixels.

◆ operator=()

SpriteRenderComponent & SpriteRenderComponent::operator= ( const SpriteRenderComponent & )
delete

◆ Render()

void SpriteRenderComponent::Render ( IRenderer * pRenderer)
overridevirtual

Renders the sprite using the provided renderer. Applies flip settings and position based on the rectangle.

Parameters
pRendererThe renderer used for drawing.

Implements RenderComponent.

◆ SetNewDimensions()

void SpriteRenderComponent::SetNewDimensions ( float x,
float y )

Sets new dimensions (width and height) for the sprite's rectangle.

Parameters
xWidth of the sprite.
yHeight of the sprite.

◆ SetNewPositions()

void SpriteRenderComponent::SetNewPositions ( float x,
float y )

Sets a new position (x, y) for the sprite's rectangle.

Parameters
xX-position of the sprite.
yY-position of the sprite.

◆ SetTexture()

void SpriteRenderComponent::SetTexture ( Texture * pTexture)
virtual

Sets or updates the texture used by this sprite. Also updates internal texture dimensions.

Parameters
pTexturePointer to the new texture.

Member Data Documentation

◆ mDrawOrder

int SpriteRenderComponent::mDrawOrder
protected

Drawing order priority.

◆ mFlip

IRenderer::Flip SpriteRenderComponent::mFlip = IRenderer::Flip::None

Flip mode (none, horizontal, vertical, both) for sprite rendering.

◆ mRectangle

Rectangle SpriteRenderComponent::mRectangle { Vector2(-16,-16),Vector2(32,32) }

The rectangle defining sprite position and size, relative to the actor.

◆ mTexHeight

int SpriteRenderComponent::mTexHeight
protected

Internal texture height (updated with SetTexture).

◆ mTexture

Texture* SpriteRenderComponent::mTexture
protected

The texture used for rendering this sprite.

◆ mTexWidth

int SpriteRenderComponent::mTexWidth
protected

Internal texture width (updated with SetTexture).


The documentation for this class was generated from the following files: