### Navigation

- index
- modules |
- next |
- previous |
- Grease v0.3 documentation »

# `grease.component` – Entity Data Containers

Components store all entity data in a given `World`. You can think of components as tables with entities as their primary keys. Like database tables, components are defined with a “schema” that specifies the data fields. Each field in a component has a name and a type.

Component objects themselves have a dict-like interface with entities as keys and data records as values. An application will typically interact with components via entity attributes, entity extents or by joining them. For more information see:

- `Entity` class.
- `EntityExtent` class.
- `join()` method of ComponentParts.

See also defining custom components in the tutorial.

exception `grease.component.``ComponentError`

  General component error

class `grease.component.``Component`(**fields)

  General component with a configurable schema

  The field schema is defined via keyword args where the arg name is the field name and the value is the type object.

  The following types are supported for fields:

  - `int`
  - `float`
  - `bool`
  - `str`
  - `object`
  - `Vec2d`
  - `Vec2dArray`
  - `RGBA`
  - `Rect`
  `set`(entity, data=None, **data_kw)

    Set the component data for an entity, adding it to the component if it is not already a member.

    If data is specified, its data for the new entity’s fields are copied from its attributes, making it easy to copy another entity’s data. Keyword arguments are also matched to fields. If both a data attribute and keyword argument are supplied for a single field, the keyword arg is used.

  `step`(dt)

    Update the component for the next timestep

class `grease.component.``Position`

  Predefined component that stores position and orientation info for entities.

  Fields:

  - position (Vec2d) – Position vector
  - angle (float) – Angle, in degrees

class `grease.component.``Transform`

  Predefined component that stores offset, shear, rotation and scale info for entity shapes.

  Fields:

  - offset (Vec2d)
  - shear (Vec2d)
  - rotation (float)
  - scale (float, default 1.0)

class `grease.component.``Movement`

  Predefined component that stores velocity, acceleration and rotation info for entities.

  Fields:

  - velocity (Vec2d) – Rate of change of entity position
  - accel (Vec2d) – Rate of change of entity velocity
  - rotation (Vec2d) – Rate of change of entity angle, in degrees/time

class `grease.component.``Shape`

  Predefined component that stores shape vertices for entities

  - closed (bool) – If the shapes is closed implying an edge between last and first vertices.
  - verts (Vec2dArray) – Array of vertex points

class `grease.component.``Renderable`

  Predefined component that identifies entities to be rendered and provides their depth and color.

  - depth (float) – Drawing depth, can be used to determine z-order

      while rendering.

  - color (color.RGBA) – Color used for entity. The effect of this

      field depends on the renderer.

class `grease.component.``Collision`

  Predefined component that stores collision masks to determine which entities can collide.

  Fields:

  - aabb (Rect) – The axis-aligned bounding box for the entity.

      This is used for broad-phase collision detection.

  - radius (float) – The collision radius of the entity, used for narrow-phase

      collision detection. The exact meaning of this value depends on the collision system in use.

  - from_mask (int) – A bitmask that determines what entities this object

      can collide with.

  - into_mask (int) – A bitmask that determines what entities can collide

      with this object.

  When considering an entity A for collision with entity B, A’s `from_mask` is bit ANDed with B’s `into_mask`. If the result is nonzero (meaning 1 or more bits is set the same for each) then the collision test is made. Otherwise, the pair cannot collide.

  The default value for both of these masks is `0xffffffff`, which means that all entities will collide with each other by default.

### Navigation

- index
- modules |
- next |
- previous |
- Grease v0.3 documentation »