Struct specs::world::EntityBuilder [] [src]

pub struct EntityBuilder<'a> {
    pub entity: Entity,
    pub world: &'a World,
    // some fields omitted
}

The entity builder, allowing to build an entity together with its components.

Examples

use specs::prelude::*;
use specs::storage::HashMapStorage;

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

The (already created) entity for which components will be inserted.

A reference to the World for component insertions.

Methods

impl<'a> EntityBuilder<'a>
[src]

[src]

Add a Marker to the entity by fetching the associated allocator.

Examples

use specs::prelude::*;
use specs::saveload::{U64Marker, U64MarkerAllocator};

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]

[src]

Appends a component and associates it with the entity.

Panics

Panics if the component hasn't been register()ed in the World.

[src]

Finishes the building and returns the entity.

Trait Implementations

impl<'a> Drop for EntityBuilder<'a>
[src]

[src]

Executes the destructor for this type. Read more

Auto Trait Implementations

impl<'a> Send for EntityBuilder<'a>

impl<'a> Sync for EntityBuilder<'a>