gdk-graphics 0a0aef92e917cfbac53dffbc32c295e4de914093
Loading...
Searching...
No Matches
gdk::graphics::sprite_animation Class Referencefinal

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.

Detailed Description

non-interpolated 2d sprite animation

Member Enumeration Documentation

◆ play_mode

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.

Constructor & Destructor Documentation

◆ sprite_animation()

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.

Parameters
aFrameDatathe frames, in the order they play, positioned in texels
aTextureWidththe sheet's width in texels
aTextureHeightthe sheet's height in texels
aPlayModewhether 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.

Member Function Documentation

◆ at()

normalized_frame gdk::graphics::sprite_animation::at ( time_type aTime) const
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.

◆ has_finished()

bool gdk::graphics::sprite_animation::has_finished ( time_type aTime) const
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.


The documentation for this class was generated from the following file: