public final class Entity extends Object
The entity convenience class.
In artemis-odb, entities are represented by an int for performance reasons. For convenience, Entity class is also supported.
Entity instances and ids get recycled. It is not safe to retain a reference to an Entity after it has been deleted from the world.
Cannot be instantiated outside the framework, you must create new entities using World. The world creates entities via it's entity manager.
Modifier | Constructor and Description |
---|---|
protected |
Entity(World world,
int id)
Creates a new
Entity instance in the given world. |
Modifier and Type | Method and Description |
---|---|
void |
deleteFromWorld()
Delete the entity from the world.
|
EntityEdit |
edit()
Get entity editor.
|
boolean |
equals(Entity o)
id equality
|
boolean |
equals(Object o)
id equality
|
<T extends Component> |
getComponent(Class<T> type)
Slower retrieval of components from this entity.
|
Component |
getComponent(ComponentType type)
Retrieves component from this entity.
|
protected BitVector |
getComponentBits()
Returns a BitVector 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 |
getCompositionId() |
int |
getId()
The internal id for this entity within the framework.
|
World |
getWorld()
Returns the world this entity belongs to.
|
int |
hashCode() |
boolean |
isActive()
Checks if the entity has been added to the world and has not been
deleted from it.
|
String |
toString() |
protected Entity(World world, int id)
Entity
instance in the given world.
This will only be called by the world via it's entity manager, and not directly by the user, as the world handles creation of entities.
world
- the world to create the entity inid
- the id to setpublic int getId()
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.
protected BitVector getComponentBits()
public EntityEdit edit()
public boolean isActive()
If the entity has been disabled this will still return true.
true
if it's activepublic Component getComponent(ComponentType type)
Minimize usage of this. Use ComponentMapper
instead.
type
- in order to retrieve the component fast you must provide a
ComponentType instance for the expected componentnull
if none is foundpublic <T extends Component> T getComponent(Class<T> type)
Minimize usage of this. Use ComponentMapper
instead.
T
- the expected return component class typetype
- the expected return component class typenull
if none is foundpublic Bag<Component> getComponents(Bag<Component> fillBag)
You need to reset the bag yourself if you intend to fill it more than once.
fillBag
- the bag to put the components intopublic void deleteFromWorld()
public World getWorld()
public int getCompositionId()
public boolean equals(Entity o)
Copyright © 2019. All rights reserved.