Struct specs::EntityBuilder
[−]
[src]
pub struct EntityBuilder<'a> { pub entity: Entity, pub world: &'a World, }
The entity builder, allowing to build an entity together with its components.
Examples
use specs::{Component, DenseVecStorage, HashMapStorage, World}; struct Health(f32); impl Component for Health { type Storage = HashMapStorage<Self>; } struct Pos { x: f32, y: f32, } impl Component for Pos { type Storage = DenseVecStorage<Self>; } let mut world = World::new(); world.register::<Health>(); world.register::<Pos>(); let entity = world .create_entity() // This call returns `EntityBuilder` .with(Health(4.0)) .with(Pos { x: 1.0, y: 3.0 }) .build(); // Returns the `Entity`
Fields
entity: Entity
The (already created) entity for which components will be inserted.
world: &'a World
A reference to the World
for component insertions.
Methods
impl<'a> EntityBuilder<'a>
[src]
pub fn marked<M>(self) -> Self where
M: Marker,
[src]
M: Marker,
Add a Marker
to the entity by fetching the associated allocator.
Examples
use specs::saveload::{U64Marker, U64MarkerAllocator}; use specs::World; let mut world = World::new(); world.register::<U64Marker>(); world.add_resource(U64MarkerAllocator::new()); world .create_entity() /* .with(Component1) */ .marked::<U64Marker>() .build();
Panics
Panics in case there's no allocator added to the World
.
impl<'a> EntityBuilder<'a>
[src]
pub fn with<T: Component>(self, c: T) -> Self
[src]
Appends a component with the default component id.
Panics
Panics if the component hasn't been register()
ed in the
World
.
pub fn with_id<T: Component>(self, c: T, id: usize) -> Self
[src]
Appends a component with a component id.
Panics
Panics if the component hasn't been register_with_id()
ed in the
World
.
pub fn build(self) -> Entity
[src]
Finishes the building and returns the entity.