|
gdk-graphics 0a0aef92e917cfbac53dffbc32c295e4de914093
|
non-interpolated 2d sprite animation More...
#include <sprite_animation.h>
Classes | |
| struct | frame |
| animation frame position and size in texels More... | |
| struct | normalized_frame |
| animation frame position and size in normalized texture coordinate space More... | |
Public Types | |
| enum class | play_mode { loop , once } |
| what happens when the animation reaches its end More... | |
| using | normalized_texture_coordinate_type = float |
| using | time_type = float |
| using | texel_coordinate_type = int |
Public Member Functions | |
| normalized_frame | at (time_type aTime) const |
| the frame showing at the given time, in normalized texture coordinates. | |
| bool | has_finished (time_type aTime) const |
| whether a once animation has played out by the given time. | |
| time_type | length () const |
| how long one cycle of the animation lasts, the total of its frames' lengths | |
| std::size_t | frame_count () const |
| how many frames the animation has | |
| sprite_animation (std::span< const frame > aFrameData, texel_coordinate_type aTextureWidth, texel_coordinate_type aTextureHeight, play_mode aPlayMode=play_mode::loop) | |
| builds an animation from frames cut out of a sprite sheet. | |
non-interpolated 2d sprite animation
|
strong |
what happens when the animation reaches its end
| Enumerator | |
|---|---|
| loop | start again. The default, and what an idle or walk cycle wants. |
| once | stop on the last frame. has_finished() then reports true. |
| gdk::graphics::sprite_animation::sprite_animation | ( | std::span< const frame > | aFrameData, |
| texel_coordinate_type | aTextureWidth, | ||
| texel_coordinate_type | aTextureHeight, | ||
| play_mode | aPlayMode = play_mode::loop ) |
builds an animation from frames cut out of a sprite sheet.
| aFrameData | the frames, in the order they play, positioned in texels |
| aTextureWidth | the sheet's width in texels |
| aTextureHeight | the sheet's height in texels |
| aPlayMode | whether it loops or stops on the last frame |
Throws if there are no frames, if any frame's length is not greater than zero, if the sheet's dimensions are not positive, or if a frame does not fit inside the sheet.
|
nodiscard |
the frame showing at the given time, in normalized texture coordinates.
aTime may be any value. A looping animation wraps it, so a caller can pass the total time elapsed without doing the arithmetic itself; negative times wrap too. A once animation clamps instead: before it starts it shows the first frame, after it ends it holds the last.
|
nodiscard |
whether a once animation has played out by the given time.
Always false for a looping animation, which never finishes. True from the moment the last frame has been shown for its full length, which is when the animation's length has elapsed.