world/world.rs
1//! World basics
2#![allow(dead_code)]
3
4use nya_ecs::{World, component};
5
6struct Point(i32, i32);
7component!(Point);
8
9struct Tag;
10component!(Tag);
11
12struct Count(i32);
13component!(Count);
14
15fn main() {
16 let mut world = World::new();
17
18 // "spawn" / create a new entity
19 let entity_id = world.spawn();
20
21 // add an component to the entity
22 world.add(entity_id, Point(16, 8));
23
24 // add multiple components at once
25 world.add(entity_id, (Count(32), Tag));
26
27 // remove the `Tag` component
28 world.del::<Tag>(entity_id);
29
30 // returns whether an entity has a component
31 world.has::<Point>(entity_id); // true
32
33 // there are also `*_res` functions for singletons
34 // (single components not associated with any entity)
35}