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; }
/** * Add a component to this entity. * * @param component the component to add to this entity * @return this EntityEdit for chaining * @see {@link #createComponent(Class)} */ public EntityEdit add(Component component) { ComponentTypeFactory tf = world.getComponentManager().typeFactory; return add(component, tf.getTypeFor(component.getClass())); }
/** * Remove component by its type. * * @param type the class type of component to remove from this entity * @return this EntityEdit for chaining */ public EntityEdit remove(Class<? extends Component> type) { ComponentTypeFactory tf = world.getComponentManager().typeFactory; return remove(tf.getTypeFor(type)); }
private static void associate( ComponentTypeFactory tf, Bag<Class<? extends Component>> types, BitSet componentBits) { for (Class<? extends Component> t : types) { componentBits.set(tf.getIndexFor(t)); } }