Created
August 7, 2017 21:03
-
-
Save torkleyy/4cb4c65f5efa01ba682958151dae55d1 to your computer and use it in GitHub Desktop.
Creating entities in Specs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
impl<'a> System<'a> for EntitiyCreator { | |
type SystemData = (Entities<'a>, WriteStorage<'a, Pos>); | |
fn run(&mut self, (entities, pos): Self::SystemData) { | |
let a = entities.create(); | |
let b = entities.create(); | |
pos.insert(a, Pos::new(2, 4)); | |
pos.insert(b, Pos::new(3, 5)); | |
} | |
} | |
// Now, if you want to insert many components for these new entities, | |
// it might be better to use `LazyUpdate` in order to avoid fetching many | |
// storages mutably: | |
impl<'a> System<'a> for LazyCreator { | |
type SytemData = (Entities<'a>, Fetch<'a, LazyUpdate>); | |
fn run(&mut self, (entities, lazy): Self::SystemData) { | |
let a = entities.create(); | |
// These updates will be applied at the end of this frame | |
lazy.insert(a, Pos::new(2, 5)); | |
lazy.insert(a, Vel::new(0, 1)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment