4#include <nlohmann/json.hpp>
46 const nlohmann::json &data) {
49 animation.elapsedTime = data.value(
"elapsedTime", 0.0f);
50 animation.currentFrame =
51 data.value(
"currentFrame",
static_cast<std::uint16_t
>(0));
52 animation.totalFrames =
53 data.value(
"totalFrames",
static_cast<std::uint16_t
>(1));
54 animation.frameWidth =
55 data.value(
"frameWidth",
static_cast<std::uint16_t
>(0));
56 animation.frameHeight =
57 data.value(
"frameHeight",
static_cast<std::uint16_t
>(0));
58 animation.startX = data.value(
"startX",
static_cast<std::uint16_t
>(0));
59 animation.startY = data.value(
"startY",
static_cast<std::uint16_t
>(0));
60 animation.columns = data.value(
"columns",
static_cast<std::uint16_t
>(0));
61 animation.paddingX = data.value(
"paddingX",
static_cast<std::uint16_t
>(0));
62 animation.paddingY = data.value(
"paddingY",
static_cast<std::uint16_t
>(0));
63 animation.loop = data.value(
"loop",
true);
64 animation.playing = data.value(
"playing",
true);
65 animation.reverse = data.value(
"reverse",
false);
void animationFromJson(rtk::ecs::Registry ®, std::size_t entity, const nlohmann::json &data)
Adds an Animation to an entity from its blueprint data.
Definition Animation.hpp:45
Sprite sheet animation played by changing the texture rectangle.
Definition Animation.hpp:17
uint16_t paddingX
Horizontal gap between frames.
Definition Animation.hpp:31
float elapsedTime
Time spent on the current frame.
Definition Animation.hpp:19
uint16_t startY
Y of the first frame in the sheet.
Definition Animation.hpp:28
uint16_t startX
X of the first frame in the sheet.
Definition Animation.hpp:27
uint16_t paddingY
Vertical gap between rows.
Definition Animation.hpp:32
bool reverse
Plays the frames backwards.
Definition Animation.hpp:36
bool playing
Advances frames while true.
Definition Animation.hpp:35
uint16_t frameHeight
Frame height in the sheet, in pixels.
Definition Animation.hpp:25
uint16_t currentFrame
Index of the visible frame.
Definition Animation.hpp:21
uint16_t columns
Frames per row, 0 for a single row.
Definition Animation.hpp:30
float frameDuration
Time each frame stays visible, in seconds.
Definition Animation.hpp:18
bool loop
Restarts after the last frame.
Definition Animation.hpp:34
uint16_t frameWidth
Frame width in the sheet, in pixels.
Definition Animation.hpp:24
uint16_t totalFrames
Number of frames in the animation.
Definition Animation.hpp:22