Every entities are link to one or many components. The components are the attributes of entities.
A component don't have a logic, it is use to store data only.
Components are store in the ECS/Components with one component per file, in the namespace ECS/components.
Copy namespace ECS {
namespace components {
class ParallaxComponent {
public:
ParallaxComponent(float scrollSpeed, float backgroundWidth): _scrollSpeed(scrollSpeed), _backgroundWidth(backgroundWidth) {}
float getScrollSpeed() const { return _scrollSpeed; }
float getBackgroundWidth() const { return _backgroundWidth; }
void setScrollSpeed(const float &scrollSpeed);
void setBackgroundWidth(const float &backgroundWidth);
private:
float _scrollSpeed;
float _backgroundWidth;
};
}
}
Copy ParallaxComponent(float scrollSpeed, float backgroundWidth): _scrollSpeed(scrollSpeed), _backgroundWidth(backgroundWidth) {}
Variable are store in private, and we can access or modify with getter and setter only:
Copy float getScrollSpeed() const { return _scrollSpeed; }
float getBackgroundWidth() const { return _backgroundWidth; }
Copy void setScrollSpeed(const float &scrollSpeed);
void setBackgroundWidth(const float &backgroundWidth);