Ejemplo n.º 1
0
 /**
  * Faster removal of components from a entity.
  *
  * @param type the type of component to remove from this entity
  * @return this EntityEdit for chaining
  */
 public EntityEdit remove(ComponentType type) {
   if (componentBits.get(type.getIndex())) {
     world.getComponentManager().removeComponent(entity, type);
     componentBits.clear(type.getIndex());
   }
   return this;
 }
Ejemplo n.º 2
0
  public <T extends Component> T create(Class<T> componentKlazz) {
    ComponentManager componentManager = world.getComponentManager();
    T component = componentManager.create(entity, componentKlazz);

    ComponentTypeFactory tf = world.getComponentManager().typeFactory;
    ComponentType componentType = tf.getTypeFor(componentKlazz);
    componentBits.set(componentType.getIndex());

    return component;
  }
Ejemplo n.º 3
0
  /**
   * Faster adding of components into the entity.
   *
   * <p>Not necessary to use this, but in some cases you might need the extra performance.
   *
   * @param component the component to add
   * @param type the type of the component
   * @return this EntityEdit for chaining
   * @see #createComponent(Class)
   */
  public EntityEdit add(Component component, ComponentType type) {
    if (type.getTaxonomy() != Taxonomy.BASIC) {
      throw new InvalidComponentException(
          component.getClass(), "Use Entity#createComponent for adding non-basic component types");
    }
    world.getComponentManager().addComponent(entity, type, component);

    componentBits.set(type.getIndex());

    return this;
  }