xecs.Transform2#

class xecs.Transform2[source]#

Bases: Component

Describes the position and orientation of an entity in 2D space.

Methods

create_pool

Create a preallocated pool of components.

fill_random

Create a transforms with random values.

Attributes

component_ids

Maps each component type to a unique ID.

translation

The translation of the entity.

rotation

The rotation of the entity.

classmethod create_pool(capacity)#

Create a preallocated pool of components.

Parameters:

capacity (int) – The maximum number of components the pool can hold.

Returns:

The component pool.

Return type:

ComponentPool[Self]

fill_random(generator, min_translation=(0.0, 0.0), max_translation=(10.0, 0.0))[source]#

Create a transforms with random values.

Parameters:
  • generator (Generator) – The random number generator to use.

  • min_translation (tuple[float, float]) – The minimum (x, y) coordinate.

  • max_translation (tuple[float, float]) – The maximum (x, y) coordinate.

Return type:

None

component_ids: ClassVar[dict[type[Component], ComponentId]] = {<class 'xecs._internal.entity_id.EntityId'>: 0, <class 'xecs._internal.transform2.Transform2'>: 1}#

Maps each component type to a unique ID. This is automatically populated by subclasses.

rotation: Float32#

The rotation of the entity.

translation: Vec2#

The translation of the entity.