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/core/api.h"
6#include "flint/graphics/drawable.h"
7#include "flint/graphics/gpu/gpu-texture.h"
8#include "flint/graphics/types/color.h"
9#include "flint/math/types.h"
10
11namespace Flint {
12
19 class Sprite : public Drawable {
20 public:
27 FLINT_API explicit Sprite(GPUTexture *texture);
28
32 FLINT_API void emit(RenderQueue &queue) const override;
33
39 FLINT_API void setTextureRect(const IntRect &rect);
45 FLINT_API void setPosition(const Vec2f &pos);
51 FLINT_API void setScale(const Vec2f &scale);
57 FLINT_API void setOrigin(const Vec2f &origin);
63 FLINT_API void setRotation(float rotation);
69 FLINT_API void setColor(const Color &color);
75 FLINT_API void move(const Vec2f &offset);
76
78 FLINT_API const FloatRect &getSrcRect() const;
79
81 FLINT_API const FloatRect &getDstRect() const;
83 FLINT_API const Vec2f &getPosition() const;
85 FLINT_API const Vec2f &getScale() const;
87 FLINT_API float getRotation() const;
89 FLINT_API const Vec2f &getOrigin() const;
91 FLINT_API const Color &getColor() const;
92
93 private:
94 FloatRect m_srcRect = {
95 {0, 0},
96 {0, 0}
97 };
98 FloatRect m_dstRect = {
99 {0, 0},
100 {0, 0}
101 };
102 Vec2f m_position = {0, 0};
103 Vec2f m_scale = {1, 1};
104 float m_rotation = 0.0f;
105 Vec2f m_origin = {0, 0};
106 Color m_color = {255, 255, 255, 255};
107 };
108
109}
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:21
Batches drawables into sorted geometry, primitive, and custom execution passes for GPURenderer.
A 2-D textured quad that references a GPUTexture.
Definition sprite.h:19
FLINT_API void setTextureRect(const IntRect &rect)
Set the source rectangle (sub-region) within the texture.
FLINT_API void setScale(const Vec2f &scale)
Set per-axis scale factors.
FLINT_API void emit(RenderQueue &queue) const override
Emit this drawable's rendering work for the current frame.
FLINT_API const FloatRect & getDstRect() const
Get the current destination rectangle in world space.
FLINT_API void setColor(const Color &color)
Set the RGBA tint color multiplied against the texture.
FLINT_API const Color & getColor() const
Get the current tint color.
FLINT_API const FloatRect & getSrcRect() const
Get the current source rectangle in texture space.
FLINT_API const Vec2f & getScale() const
Get the current scale factors.
FLINT_API const Vec2f & getPosition() const
Get the current world-space position.
FLINT_API void move(const Vec2f &offset)
Translate the sprite by offset.
FLINT_API float getRotation() const
Get the current rotation angle in radians.
FLINT_API void setOrigin(const Vec2f &origin)
Set the local pivot point used for rotation and positioning.
FLINT_API const Vec2f & getOrigin() const
Get the current local pivot point.
FLINT_API Sprite(GPUTexture *texture)
Construct a Sprite backed by texture.
FLINT_API void setRotation(float rotation)
Set the rotation angle.
FLINT_API void setPosition(const Vec2f &pos)
Set the world-space position of the sprite's local origin.
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