Add player sprite

This commit is contained in:
Daniel Lynn 2021-07-16 23:33:54 -05:00
parent 4ab62ea921
commit 04fe103b25
Signed by: daniel
GPG Key ID: 28496A140E180A9D
2 changed files with 15 additions and 2 deletions

View File

@ -18,5 +18,6 @@ fn main() {
.insert_resource(ClearColor(Color::rgb(0.0, 0.0, 0.0)))
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())
.add_startup_system(add_player.system())
.run();
}

View File

@ -31,11 +31,23 @@ pub fn setup(
}
}
pub fn add_player(mut commands: Commands) {
pub fn add_player(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
let player_sprite = materials.add(asset_server.load("marshmallow.png").into());
commands
.spawn()
.insert(Player)
.insert(Name("Player 1".to_string()));
.insert(Name("Player 1".to_string()))
.insert_bundle(SpriteBundle {
material: player_sprite,
sprite: Sprite::new(Vec2::new(64.0, 64.0)),
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 1.0)),
..Default::default()
});
}
pub fn greet_player(