How a texture is cut into frames, numbered from 0.
More...
#include <aegis2d/render/sprite_sheet.hpp>
How a texture is cut into frames, numbered from 0.
Animations show the frames in turn (ecs::Animation); a sprite draws one with source() as its Sprite::source:
renderer.draw({.texture = player, .position = ..., .size = ..., .source = sheet.source(2)});
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.
TextureManager keeps the sheet of each texture (TextureManager::load_sheet()).
◆ SpriteSheet() [1/2]
| aegis2d::render::SpriteSheet::SpriteSheet |
( |
TextureSize |
texture | ) |
|
|
explicit |
A sheet whose only frame is the whole texture.
- Parameters
-
| texture | Size of the texture. |
- Exceptions
-
| std::invalid_argument | if a dimension is not above 0. |
◆ SpriteSheet() [2/2]
Frames at the given rectangles, for sheets packed by hand or by a tool.
- Parameters
-
| texture | Size of the texture. |
| frames | Rectangle of each frame, in the order of their numbers. |
- Exceptions
-
| std::invalid_argument | if a texture dimension is not above 0, frames is empty, or a frame is empty or goes past the texture. |
◆ frame()
| PixelRect aegis2d::render::SpriteSheet::frame |
( |
std::size_t |
index | ) |
const |
Rectangle of a frame.
- Parameters
-
| index | Frame number, from 0. |
- Returns
- The frame, in pixels.
- Exceptions
-
| std::out_of_range | if index is not below size(). |
◆ grid()
Frames of the same size laid out in a grid, numbered left to right, then top to bottom.
- Parameters
-
| texture | Size of the texture. |
| frame | Size of one frame. |
| count | Number of frames; 0 for every whole frame of the grid, so a sheet whose last row is not full lists the frames it has. |
| spacing | Pixels between two neighbouring frames, on both axes; none around the grid. |
- Returns
- The sheet.
- Exceptions
-
| std::invalid_argument | if a size is not above 0, spacing is negative, not even one frame fits, or count is more than the frames that fit. |
◆ size()
| std::size_t aegis2d::render::SpriteSheet::size |
( |
| ) |
const |
|
noexcept |
Number of frames.
- Returns
- At least 1.
◆ source()
| Rect aegis2d::render::SpriteSheet::source |
( |
std::size_t |
index | ) |
const |
Part of the texture to draw for a frame, as Sprite::source takes it.
- Parameters
-
| index | Frame number, from 0. |
- Returns
- The frame in normalized texture coordinates.
- Exceptions
-
| std::out_of_range | if index is not below size(). |
◆ texture()
| TextureSize aegis2d::render::SpriteSheet::texture |
( |
| ) |
const |
|
noexcept |
Size of the texture.
- Returns
- The size given when the sheet was made.
The documentation for this class was generated from the following file: