> For the complete documentation index, see [llms.txt](https://redboard.gitbook.io/r-type-1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://redboard.gitbook.io/r-type-1/client/ecs/systems/create-a-new-system.md).

# Create a new system

Step by step to create a system

System are the logic of component and entities.\
They use component data to process and do something like modify component data or send signal to a server.\
Components are store in the ECS/Systems with one component per file, in the namespace ECS/systems.

Here an example of a system:

```cpp
namespace ECS {
    namespace systems {
        class ParallaxSystem {
        public:
            void update(Registry &ecs, float deltaTime) {
                try {
                    auto &parallaxComponents = ecs.get_components<components::ParallaxComponent>();
                    auto &positionComponents = ecs.get_components<components::PositionComponent>();

                    for (size_t i = 0; i < parallaxComponents.size() && i < positionComponents.size(); ++i) {
                        auto &parallax = parallaxComponents[i];
                        auto &position = positionComponents[i];

                        if (parallax && position) {
                            float scrollSpeed = parallax->getScrollSpeed();
                            float newX = position->getX() + deltaTime * scrollSpeed;

                            float backgroundWidth = parallax->getBackgroundWidth() / 2;
                            if (newX < -backgroundWidth)
                                newX += backgroundWidth;
                            position->setX(newX);
                        }
                    }
                } catch (std::exception &e) {
                    std::cerr << e.what() << std::endl;
                }
            }
        };
    }
}
```

It is compose of an update() function with argument:

```cpp
void update(Registry &ecs, float deltaTime);
```

System class get all entity's components from ecs with ecs.get\_components\<components>(arguments). In the example, we get two components lists:

```cpp
auto &parallaxComponents = ecs.get_components<components::ParallaxComponent>();
auto &positionComponents = ecs.get_components<components::PositionComponent>();
```

It use to get the list of a specific component, and process all of them directly with a loop:

```cpp
for (size_t i = 0; i < parallaxComponents.size() && i < positionComponents.size(); ++i) {
    auto &parallax = parallaxComponents[i];
    auto &position = positionComponents[i];

    if (parallax && position) {
        float scrollSpeed = parallax->getScrollSpeed();
        float newX = position->getX() + deltaTime * scrollSpeed;
        float backgroundWidth = parallax->getBackgroundWidth() / 2;

        if (newX < -backgroundWidth)
            newX += backgroundWidth;
        position->setX(newX);
    }
}
```

On this example, we loop on every parallaxComponents and positionComponent, and process them.\
Here, we move automatically the parallax in the X direction using parallax and position data in each component.
