com.artemis
Class Entity

java.lang.Object
  extended by com.artemis.Entity

public final class Entity
extends java.lang.Object

The entity class. Cannot be instantiated outside the framework, you must create new entities using World.

Author:
Arni Arent

Constructor Summary
protected Entity(World world, int id)
           
 
Method Summary
 Entity addComponent(Component component)
          Add a component to this entity.
 Entity addComponent(Component component, ComponentType type)
          Faster adding of components into the entity.
 void addToWorld()
          Refresh all changes to components for this entity.
 void changedInWorld()
          This entity has changed, a component added or deleted.
 void deleteFromWorld()
          Delete this entity from the world.
 void disable()
          Disable the entity from being processed.
 void enable()
          (Re)enable the entity in the world, after it having being disabled.
<T extends Component>
T
getComponent(java.lang.Class<T> type)
          Slower retrieval of components from this entity.
 Component getComponent(ComponentType type)
          This is the preferred method to use when retrieving a component from a entity.
protected  java.util.BitSet getComponentBits()
          Returns a BitSet instance containing bits of the components the entity possesses.
 Bag<Component> getComponents(Bag<Component> fillBag)
          Returns a bag of all components this entity has.
 int getId()
          The internal id for this entity within the framework.
protected  java.util.BitSet getSystemBits()
          Returns a BitSet instance containing bits of the components the entity possesses.
 java.util.UUID getUuid()
          Get the UUID for this entity.
 World getWorld()
          Returns the world this entity belongs to.
 boolean isActive()
          Checks if the entity has been added to the world and has not been deleted from it.
 boolean isEnabled()
          Will check if the entity is enabled in the world.
 Entity removeComponent(java.lang.Class<? extends Component> type)
          Remove component by its type.
 Entity removeComponent(Component component)
          Removes the component from this entity.
 Entity removeComponent(ComponentType type)
          Faster removal of components from a entity.
protected  void reset()
          Make entity ready for re-use.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Entity

protected Entity(World world,
                 int id)
Method Detail

getId

public int getId()
The internal id for this entity within the framework. No other entity will have the same ID, but ID's are however reused so another entity may acquire this ID if the previous entity was deleted.

Returns:
id of the entity.

getComponentBits

protected java.util.BitSet getComponentBits()
Returns a BitSet instance containing bits of the components the entity possesses.

Returns:

getSystemBits

protected java.util.BitSet getSystemBits()
Returns a BitSet instance containing bits of the components the entity possesses.

Returns:

reset

protected void reset()
Make entity ready for re-use. Will generate a new uuid for the entity.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

addComponent

public Entity addComponent(Component component)
Add a component to this entity.

Parameters:
component - to add to this entity
Returns:
this entity for chaining.

addComponent

public Entity addComponent(Component component,
                           ComponentType type)
Faster adding of components into the entity. Not neccessery to use this, but in some cases you might need the extra performance.

Parameters:
component - the component to add
type - of the component
Returns:
this entity for chaining.

removeComponent

public Entity removeComponent(Component component)
Removes the component from this entity.

Parameters:
component - to remove from this entity.
Returns:
this entity for chaining.

removeComponent

public Entity removeComponent(ComponentType type)
Faster removal of components from a entity.

Parameters:
component - to remove from this entity.
Returns:
this entity for chaining.

removeComponent

public Entity removeComponent(java.lang.Class<? extends Component> type)
Remove component by its type.

Parameters:
type -
Returns:
this entity for chaining.

isActive

public boolean isActive()
Checks if the entity has been added to the world and has not been deleted from it. If the entity has been disabled this will still return true.

Returns:
if it's active.

isEnabled

public boolean isEnabled()
Will check if the entity is enabled in the world. By default all entities that are added to world are enabled, this will only return false if an entity has been explicitly disabled.

Returns:
if it's enabled

getComponent

public Component getComponent(ComponentType type)
This is the preferred method to use when retrieving a component from a entity. It will provide good performance. But the recommended way to retrieve components from an entity is using the ComponentMapper.

Parameters:
type - in order to retrieve the component fast you must provide a ComponentType instance for the expected component.
Returns:

getComponent

public <T extends Component> T getComponent(java.lang.Class<T> type)
Slower retrieval of components from this entity. Minimize usage of this, but is fine to use e.g. when creating new entities and setting data in components.

Type Parameters:
T - the expected return component type.
Parameters:
type - the expected return component type.
Returns:
component that matches, or null if none is found.

getComponents

public Bag<Component> getComponents(Bag<Component> fillBag)
Returns a bag of all components this entity has. You need to reset the bag yourself if you intend to fill it more than once.

Parameters:
fillBag - the bag to put the components into.
Returns:
the fillBag with the components in.

addToWorld

public void addToWorld()
Refresh all changes to components for this entity. After adding or removing components, you must call this method. It will update all relevant systems. It is typical to call this after adding components to a newly created entity.


changedInWorld

public void changedInWorld()
This entity has changed, a component added or deleted.


deleteFromWorld

public void deleteFromWorld()
Delete this entity from the world.


enable

public void enable()
(Re)enable the entity in the world, after it having being disabled. Won't do anything unless it was already disabled.


disable

public void disable()
Disable the entity from being processed. Won't delete it, it will continue to exist but won't get processed.


getUuid

public java.util.UUID getUuid()
Get the UUID for this entity. This UUID is unique per entity (re-used entities get a new UUID).

Returns:
uuid instance for this entity.

getWorld

public World getWorld()
Returns the world this entity belongs to.

Returns:
world of entity.


Copyright © 2012 Gamadu. All Rights Reserved.