Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
sprite_sheet.hpp
Go to the documentation of this file.
1
3#pragma once
4
5#include <aegis2d/render/export.hpp>
7
8#include <cstddef>
9#include <vector>
10
11namespace aegis2d::render {
12
14struct PixelRect {
16 int x = 0;
18 int y = 0;
20 int width = 0;
22 int height = 0;
23
25 friend constexpr bool operator==(const PixelRect&, const PixelRect&) noexcept = default;
26};
27
37class AEGIS2D_RENDER_EXPORT SpriteSheet {
38public:
42 explicit SpriteSheet(TextureSize texture);
43
49 SpriteSheet(TextureSize texture, std::vector<PixelRect> frames);
50
62 [[nodiscard]] static SpriteSheet grid(TextureSize texture, TextureSize frame,
63 std::size_t count = 0, int spacing = 0);
64
67 [[nodiscard]] std::size_t size() const noexcept;
68
71 [[nodiscard]] TextureSize texture() const noexcept;
72
77 [[nodiscard]] PixelRect frame(std::size_t index) const;
78
83 [[nodiscard]] Rect source(std::size_t index) const;
84
85private:
86 TextureSize texture_;
87 std::vector<PixelRect> frames_;
88};
89
90} // namespace aegis2d::render
How a texture is cut into frames, numbered from 0.
Definition sprite_sheet.hpp:37
std::size_t size() const noexcept
Number of frames.
static SpriteSheet grid(TextureSize texture, TextureSize frame, std::size_t count=0, int spacing=0)
Frames of the same size laid out in a grid, numbered left to right, then top to bottom.
SpriteSheet(TextureSize texture, std::vector< PixelRect > frames)
Frames at the given rectangles, for sheets packed by hand or by a tool.
SpriteSheet(TextureSize texture)
A sheet whose only frame is the whole texture.
OpenGL renderer: sprites, text and camera (client only).
Definition bitmap_font.hpp:16
Definition endpoint.hpp:85
Backend-independent renderer interface and the sprite it draws.
Rectangle of a texture, in whole pixels from its top-left corner.
Definition sprite_sheet.hpp:14
friend constexpr bool operator==(const PixelRect &, const PixelRect &) noexcept=default
Compares the rectangles.
int y
Top edge.
Definition sprite_sheet.hpp:18
int height
Height, above 0.
Definition sprite_sheet.hpp:22
int width
Width, above 0.
Definition sprite_sheet.hpp:20
int x
Left edge.
Definition sprite_sheet.hpp:16
Axis-aligned rectangle.
Definition renderer.hpp:20
Width and height of a texture, in pixels.
Definition renderer.hpp:38