Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
Loading...
Searching...
No Matches
AnimationSystem.hpp
Go to the documentation of this file.
1
8#ifndef ANIMATION_SYSTEM_HPP
9#define ANIMATION_SYSTEM_HPP
10
11#include "RType/ECS/ISystem.hpp"
13
16
17namespace rtp::client {
19 public:
20 explicit AnimationSystem(ecs::Registry& r) : _r(r) {}
21
22 void update(float dt) override {
24
25 for (auto&& [sprite, animation] : view) {
26 animation.elapsedTime += dt;
27
28 while (animation.elapsedTime >= animation.frameDuration) {
29 animation.elapsedTime -= animation.frameDuration;
30
31 animation.currentFrame = (animation.currentFrame + 1) % animation.totalFrames;
32
33 sprite.rectLeft = animation.frameLeft + animation.currentFrame * animation.frameWidth;
34 sprite.rectTop = animation.frameTop;
35 }
36 }
37 }
38 private:
40 };
41}
42#endif // ANIMATION_SYSTEM_HPP
Interface for ECS systems.
void update(float dt) override
Update system logic for one frame.
Abstract base class for all ECS systems.
Definition ISystem.hpp:57
auto zipView(this Self &self)
R-Type client namespace.
Component representing an animation.
Definition Animation.hpp:17
float elapsedTime
Time elapsed since the animation started.
Definition Animation.hpp:22
Component representing a sprite.
Definition Sprite.hpp:21