Flint Engine
Modular C++20 2D game engine powered by SDL3
Loading...
Searching...
No Matches
sprite.h
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2025-2026 Manuel Osorio
3#pragma once
4
5#include "flint/graphics/drawable.h"
6#include "flint/graphics/gpu/gpu-texture.h"
7#include "flint/graphics/types/color.h"
8#include "flint/math/types.h"
9
10namespace Flint {
11
18 class Sprite : public Drawable {
19 public:
26 explicit Sprite(GPUTexture *texture);
27
31 void emit(RenderQueue &queue) const override;
32
38 void setTextureRect(const IntRect &rect);
44 void setPosition(const Vec2f &pos);
50 void setScale(const Vec2f &scale);
56 void setOrigin(const Vec2f &origin);
62 void setRotation(float rotation);
68 void setColor(const Color &color);
74 void move(const Vec2f &offset);
75
77 const FloatRect &getSrcRect() const;
78
80 const FloatRect &getDstRect() const;
82 const Vec2f &getPosition() const;
84 const Vec2f &getScale() const;
86 float getRotation() const;
88 const Vec2f &getOrigin() const;
90 const Color &getColor() const;
91
92 private:
93 FloatRect m_srcRect = {
94 {0, 0},
95 {0, 0}
96 };
97 FloatRect m_dstRect = {
98 {0, 0},
99 {0, 0}
100 };
101 Vec2f m_position = {0, 0};
102 Vec2f m_scale = {1, 1};
103 float m_rotation = 0.0f;
104 Vec2f m_origin = {0, 0};
105 Color m_color = {255, 255, 255, 255};
106 };
107
108}
Interface for objects that contribute ordered work to a rendered frame.
Definition drawable.h:21
Owns an SDL GPU texture and its associated sampler.
Definition gpu-texture.h:20
Batches drawables into sorted geometry, primitive, and custom execution passes for GPURenderer.
void setTextureRect(const IntRect &rect)
Set the source rectangle (sub-region) within the texture.
void setRotation(float rotation)
Set the rotation angle.
Sprite(GPUTexture *texture)
Construct a Sprite backed by texture.
void setColor(const Color &color)
Set the RGBA tint color multiplied against the texture.
void emit(RenderQueue &queue) const override
Emit this drawable's rendering work for the current frame.
void setOrigin(const Vec2f &origin)
Set the local pivot point used for rotation and positioning.
void setPosition(const Vec2f &pos)
Set the world-space position of the sprite's local origin.
void setScale(const Vec2f &scale)
Set per-axis scale factors.
void move(const Vec2f &offset)
Translate the sprite by offset.
A 2-D textured quad that references a GPUTexture.
Definition sprite.h:18
const Color & getColor() const
Get the current tint color.
const FloatRect & getSrcRect() const
Get the current source rectangle in texture space.
const FloatRect & getDstRect() const
Get the current destination rectangle in world space.
float getRotation() const
Get the current rotation angle in radians.
const Vec2f & getScale() const
Get the current scale factors.
const Vec2f & getOrigin() const
Get the current local pivot point.
const Vec2f & getPosition() const
Get the current world-space position.
RGBA color with 8-bit unsigned components.
Definition color.h:13
Generic axis-aligned rectangle defined by a position and size.
Definition types.h:87