wPlot2D version: 0.1.0
A lightweight C++ library for clear and customizable 2D scientific plots.
Loading...
Searching...
No Matches
wEngine::PositionComponent Class Reference

ECS component storing the position of an entity in 2D space and supports movement tracking. More...

#include <wPositionComponent.hpp>

Inheritance diagram for wEngine::PositionComponent:
Inheritance graph

Public Member Functions

 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.
Public Member Functions inherited from wEngine::Component
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.
EntitygetParent () const
 Returns the parent entity of this component.

Additional Inherited Members

Protected Member Functions inherited from wEngine::Component
 Component ()
 Protected constructor to restrict instantiation to derived classes.

Detailed Description

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

Constructor & Destructor Documentation

◆ PositionComponent()

wEngine::PositionComponent::PositionComponent ( sf::Vector2f position = sf::Vector2f( 0.0f, 0.0f ))

Constructs a PositionComponent with the given position.

Parameters
positionInitial position (default is ( 0.0f, 0.0f )).

◆ ~PositionComponent()

virtual wEngine::PositionComponent::~PositionComponent ( )
virtualdefault

Member Function Documentation

◆ 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
newPositionThe new position.

◆ move()

void wEngine::PositionComponent::move ( const sf::Vector2f & offset)

Moves the position by an offset.

Parameters
offsetThe 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: