From b562abe976e8dc0e5ba05d60a9d2765b0a23ebc4 Mon Sep 17 00:00:00 2001 From: ModZero Date: Fri, 23 Dec 2022 17:00:57 +0100 Subject: [PATCH] Add a "pawn" that gets "rendered" above the ground layer. --- src/main.rs | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 391e6b0..bf556b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,6 +46,17 @@ impl TileTerrain { } } +#[derive(Bundle, Default)] +struct PawnBundle { + position: TilePos, + sprite: Sprite, + transform: Transform, + global_transform: GlobalTransform, + texture: Handle, + visibility: Visibility, + computed_visibility: ComputedVisibility, +} + fn make_ground_layer( commands: &mut Commands, tilemap_size: TilemapSize, @@ -90,6 +101,24 @@ fn make_ground_layer( }); } +fn make_pawn(commands: &mut Commands, texture_handle: Handle, tile_size: TilemapTileSize) { + commands.spawn(PawnBundle { + transform: Transform::from_xyz(0.0, 0.0, 1.0), + texture: texture_handle, + sprite: Sprite { + rect: Option::Some(Rect::new( + 3. * tile_size.x, + 4. * tile_size.y, + 4. * tile_size.x, + 5. * tile_size.y, + )), + ..Default::default() + }, + visibility: Visibility { is_visible: true }, + ..Default::default() + }); +} + fn startup(mut commands: Commands, asset_server: Res) { commands.spawn(Camera2dBundle::default()); @@ -98,7 +127,13 @@ fn startup(mut commands: Commands, asset_server: Res) { let tilemap_size = TilemapSize { x: 320, y: 320 }; let tile_size = TilemapTileSize { x: 32.0, y: 32.0 }; - make_ground_layer(&mut commands, tilemap_size, texture_handle, tile_size); + make_ground_layer( + &mut commands, + tilemap_size, + texture_handle.clone(), + tile_size, + ); + make_pawn(&mut commands, texture_handle, tile_size); } fn mouse_motion( @@ -116,6 +151,7 @@ fn mouse_motion( } } + fn main() { App::new() .add_plugins(