3#include "Logger/Logger.hpp"
4#include "components/Parallax.hpp"
5#include "components/Transform.hpp"
8namespace rtk::systems {
25 void onStart(rtk::ecs::Registry &)
override {
26 LOG_INFO(
"Load Parallax System");
35 void update(rtk::ecs::Registry ®,
float dt)
override {
41 for (
auto entity : view) {
42 auto *transform = transforms.get(entity);
43 auto *parallax = parallaxes.get(entity);
45 if (!transform || !parallax)
48 transform->
position.
x -= parallax->speedX * dt;
50 if (transform->position.x <= -parallax->loopWidth) {
51 transform->position.x += parallax->loopWidth * 3.0f;
59 void onStop(rtk::ecs::Registry &)
override {}
Scrolls background layers and wraps them to loop endlessly.
Definition ParallaxSystem.hpp:17
void onStop(rtk::ecs::Registry &) override
Does nothing.
Definition ParallaxSystem.hpp:59
void onStart(rtk::ecs::Registry &) override
Logs that the system is loaded.
Definition ParallaxSystem.hpp:25
void update(rtk::ecs::Registry ®, float dt) override
Moves each layer left and jumps it three tiles right once off screen.
Definition ParallaxSystem.hpp:35
Background layer that scrolls left and wraps around.
Definition Parallax.hpp:16
float x
Horizontal component.
Definition vec2.hpp:13