Claire's Game Engine
Full C++ Engine using OpenGL
|
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>
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 | |
SpriteRenderComponent & | operator= (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. | |
![]() | |
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. | |
![]() | |
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. | |
Actor * | GetOwner () 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. | |
![]() | |
Color | mColor { 255,255,255,255 } |
Protected Attributes | |
Texture * | mTexture |
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). | |
![]() | |
Actor * | mOwner = nullptr |
The actor that owns this component. | |
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.
SpriteRenderComponent::SpriteRenderComponent | ( | Actor * | pOwner, |
int | pDrawOrder = 100 ) |
Constructs a sprite render component without a texture.
pOwner | The actor that owns this component. |
pDrawOrder | The drawing order priority (higher values draw later). |
SpriteRenderComponent::SpriteRenderComponent | ( | Actor * | pOwner, |
Texture * | pTexture, | ||
int | pDrawOrder = 100 ) |
Constructs a sprite render component with an initial texture.
pOwner | The actor that owns this component. |
pTexture | The texture to be rendered. |
pDrawOrder | The drawing order priority. |
|
delete |
|
delete |
|
overridevirtual |
Gets the drawing order priority of this component. Higher values render on top of lower values.
Reimplemented from RenderComponent.
|
overridevirtual |
Returns the render type of this component (Viewport).
Implements RenderComponent.
int SpriteRenderComponent::GetTexHeight | ( | ) | const |
Gets the height of the texture used by this sprite.
int SpriteRenderComponent::GetTexWidth | ( | ) | const |
Gets the width of the texture used by this sprite.
|
delete |
|
overridevirtual |
Renders the sprite using the provided renderer. Applies flip settings and position based on the rectangle.
pRenderer | The renderer used for drawing. |
Implements RenderComponent.
void SpriteRenderComponent::SetNewDimensions | ( | float | x, |
float | y ) |
Sets new dimensions (width and height) for the sprite's rectangle.
x | Width of the sprite. |
y | Height of the sprite. |
void SpriteRenderComponent::SetNewPositions | ( | float | x, |
float | y ) |
Sets a new position (x, y) for the sprite's rectangle.
x | X-position of the sprite. |
y | Y-position of the sprite. |
|
virtual |
Sets or updates the texture used by this sprite. Also updates internal texture dimensions.
pTexture | Pointer to the new texture. |
|
protected |
Drawing order priority.
IRenderer::Flip SpriteRenderComponent::mFlip = IRenderer::Flip::None |
Flip mode (none, horizontal, vertical, both) for sprite rendering.
The rectangle defining sprite position and size, relative to the actor.
|
protected |
Internal texture height (updated with SetTexture).
|
protected |
The texture used for rendering this sprite.
|
protected |
Internal texture width (updated with SetTexture).