Flint Engine
Modular C++20 2D game engine powered by SDL3
Loading...
Searching...
No Matches
Flint::Sprite Class Reference

A 2-D textured quad that references a GPUTexture. More...

#include <flint/graphics/sprite.h>

+ Inheritance diagram for Flint::Sprite:
+ Collaboration diagram for Flint::Sprite:

Public Member Functions

FLINT_API Sprite (GPUTexture *texture)
 Construct a Sprite backed by texture.
 
FLINT_API void emit (RenderQueue &queue) const override
 Emit this drawable's rendering work for the current frame.
 
FLINT_API void setTextureRect (const IntRect &rect)
 Set the source rectangle (sub-region) within the texture.
 
FLINT_API void setPosition (const Vec2f &pos)
 Set the world-space position of the sprite's local origin.
 
FLINT_API void setScale (const Vec2f &scale)
 Set per-axis scale factors.
 
FLINT_API void setOrigin (const Vec2f &origin)
 Set the local pivot point used for rotation and positioning.
 
FLINT_API void setRotation (float rotation)
 Set the rotation angle.
 
FLINT_API void setColor (const Color &color)
 Set the RGBA tint color multiplied against the texture.
 
FLINT_API void move (const Vec2f &offset)
 Translate the sprite by offset.
 
FLINT_API const FloatRect & getSrcRect () const
 Get the current source rectangle in texture space.
 
FLINT_API const FloatRect & getDstRect () const
 Get the current destination rectangle in world space.
 
FLINT_API const Vec2f & getPosition () const
 Get the current world-space position.
 
FLINT_API const Vec2f & getScale () const
 Get the current scale factors.
 
FLINT_API float getRotation () const
 Get the current rotation angle in radians.
 
FLINT_API const Vec2f & getOrigin () const
 Get the current local pivot point.
 
FLINT_API const Color & getColor () const
 Get the current tint color.
 
- Public Member Functions inherited from Flint::Drawable
void setGPUTexture (GPUTexture *texture)
 Associate a texture with this drawable.
 
GPUTexture * getGPUTexture () const
 Get the associated GPU texture.
 

Additional Inherited Members

- Protected Attributes inherited from Flint::Drawable
GPUTexture * m_gpuTexture = nullptr
 Non-owning reference to the GPU texture asset.
 

Detailed Description

A 2-D textured quad that references a GPUTexture.

Supports position, scale, rotation, a local origin pivot, an RGBA tint, and a source rectangle for sprite-sheet animation.

Definition at line 19 of file sprite.h.

Constructor & Destructor Documentation

◆ Sprite()

FLINT_API Flint::Sprite::Sprite ( GPUTexture * texture)
explicit

Construct a Sprite backed by texture.

Parameters
textureNon-owning pointer to the GPU texture. Must remain valid for the lifetime of this Sprite.

Member Function Documentation

◆ emit()

FLINT_API void Flint::Sprite::emit ( RenderQueue & queue) const
overridevirtual

Emit this drawable's rendering work for the current frame.

Called once after submitted drawables have been sorted by DrawLayer. Implementations must enqueue work through queue rather than issuing immediate GPU commands.

Parameters
queueQueue receiving this drawable's rendering work.

Implements Flint::Drawable.

◆ move()

FLINT_API void Flint::Sprite::move ( const Vec2f & offset)

Translate the sprite by offset.

Parameters
offsetWorld-space delta to add to the current position.

◆ setColor()

FLINT_API void Flint::Sprite::setColor ( const Color & color)

Set the RGBA tint color multiplied against the texture.

Parameters
colorTint color (white = no tint).

◆ setOrigin()

FLINT_API void Flint::Sprite::setOrigin ( const Vec2f & origin)

Set the local pivot point used for rotation and positioning.

Parameters
originPivot in local (object) space.

◆ setPosition()

FLINT_API void Flint::Sprite::setPosition ( const Vec2f & pos)

Set the world-space position of the sprite's local origin.

Parameters
posWorld-space position of the sprite origin.

◆ setRotation()

FLINT_API void Flint::Sprite::setRotation ( float rotation)

Set the rotation angle.

Parameters
rotationAngle in radians.

◆ setScale()

FLINT_API void Flint::Sprite::setScale ( const Vec2f & scale)

Set per-axis scale factors.

Parameters
scaleScale (1, 1) = original texture size.

◆ setTextureRect()

FLINT_API void Flint::Sprite::setTextureRect ( const IntRect & rect)

Set the source rectangle (sub-region) within the texture.

Parameters
rectInteger pixel rectangle in texture space.

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