ECS component storing the position of an entity in 2D space and supports movement tracking.
More...
#include <wPositionComponent.hpp>
|
| PositionComponent (sf::Vector2f position=sf::Vector2f(0.0f, 0.0f)) |
| Constructs a PositionComponent with the given position.
|
virtual | ~PositionComponent ()=default |
sf::Vector2f | getPosition () const |
| Gets the current position of the component.
|
sf::Vector2f | getLastPosition () const |
| Returns the previous position (before the last move).
|
void | setPosition (sf::Vector2f newPosition) |
| Sets the 2D position to a new value.
|
void | move (const sf::Vector2f &offset) |
| Moves the position by an offset.
|
void | debugPrint () const |
| Outputs the position (x, y) to standard output for debugging.
|
virtual | ~Component ()=default |
virtual void | enable () |
virtual void | disable () |
bool | isEnabled () const |
| Checks whether the component is currently active.
|
void | setParent (Entity *parent) |
| Sets the parent entity of this component.
|
Entity * | getParent () const |
| Returns the parent entity of this component.
|
|
| Component () |
| Protected constructor to restrict instantiation to derived classes.
|
ECS component storing the position of an entity in 2D space and supports movement tracking.
This component holds a 2D vector representing the current and previous spatial position of its parent entity.
Usage Examples:
- Default position at origin:
addComponent< wEngine::PositionComponent >( );
- Custom position:
addComponent< wEngine::PositionComponent >( sf::Vector2f( 100.0f, 200.0f ) );
- Author
- Wilfried Koch
- Copyright
- © 2025 Wilfried Koch. All rights reserved.
◆ PositionComponent()
wEngine::PositionComponent::PositionComponent |
( |
sf::Vector2f | position = sf::Vector2f( 0.0f, 0.0f ) | ) |
|
Constructs a PositionComponent with the given position.
- Parameters
-
position | Initial position (default is ( 0.0f, 0.0f )). |
◆ ~PositionComponent()
virtual wEngine::PositionComponent::~PositionComponent |
( |
| ) |
|
|
virtualdefault |
◆ getPosition()
sf::Vector2f wEngine::PositionComponent::getPosition |
( |
| ) |
const |
|
nodiscard |
Gets the current position of the component.
- Returns
- The current 2D position vector.
◆ getLastPosition()
sf::Vector2f wEngine::PositionComponent::getLastPosition |
( |
| ) |
const |
|
nodiscard |
Returns the previous position (before the last move).
- Returns
- The last recorded position.
◆ setPosition()
void wEngine::PositionComponent::setPosition |
( |
sf::Vector2f | newPosition | ) |
|
Sets the 2D position to a new value.
- Parameters
-
newPosition | The new position. |
◆ move()
void wEngine::PositionComponent::move |
( |
const sf::Vector2f & | offset | ) |
|
Moves the position by an offset.
- Parameters
-
offset | The offset to add to the current position. |
Stores the current position as the last position before applying the offset.
◆ debugPrint()
void wEngine::PositionComponent::debugPrint |
( |
| ) |
const |
Outputs the position (x, y) to standard output for debugging.
The documentation for this class was generated from the following files: