3#include "components/Animation.hpp"
4#include "components/Animator.hpp"
7namespace rtk::systems {
24 void onStart(rtk::ecs::Registry &)
override {}
31 void update(rtk::ecs::Registry ®,
float dt)
override {
37 for (
auto entity : view) {
38 auto *anim = animations.get(entity);
39 auto *animator = animators.get(entity);
41 if (!anim || !animator)
44 auto stateIdx =
static_cast<std::size_t
>(animator->currentState);
45 if (stateIdx < animator->clips.size() &&
46 animator->currentState != animator->previousState) {
47 const auto ¤tClip = animator->clips[stateIdx];
49 anim->startX = currentClip.startX;
50 anim->startY = currentClip.startY;
51 anim->totalFrames = currentClip.totalFrames;
52 anim->frameDuration = currentClip.frameDuration;
53 anim->loop = currentClip.loop;
54 anim->reverse = currentClip.reverse;
55 if (currentClip.frameWidth > 0) {
56 anim->frameWidth = currentClip.frameWidth;
58 if (currentClip.frameHeight > 0) {
59 anim->frameHeight = currentClip.frameHeight;
61 anim->currentFrame = 0;
62 anim->elapsedTime = 0.0f;
64 animator->previousState = animator->currentState;
72 void onStop(rtk::ecs::Registry &)
override {}
Loads the clip of the current animator state into the Animation.
Definition AnimatorSystem.hpp:16
void onStart(rtk::ecs::Registry &) override
Does nothing.
Definition AnimatorSystem.hpp:24
void update(rtk::ecs::Registry ®, float dt) override
Restarts the animation with a new clip when the state changed.
Definition AnimatorSystem.hpp:31
void onStop(rtk::ecs::Registry &) override
Does nothing.
Definition AnimatorSystem.hpp:72
Sprite sheet animation played by changing the texture rectangle.
Definition Animation.hpp:17
State machine that picks the Animation clip of an entity.
Definition Animator.hpp:45