use bevy::{ diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, prelude::*, }; use bevy_ecs_tilemap::prelude::*; use rand::{thread_rng, Rng}; mod helpers; fn startup(mut commands: Commands, asset_server: Res) { commands.spawn(Camera2dBundle::default()); let texture_handle: Handle = asset_server.load("tiles.png"); let map_size = TilemapSize { x: 320, y: 320 }; let mut tile_storage = TileStorage::empty(map_size); let tilemap_entity = commands.spawn_empty().id(); for x in 0..320u32 { for y in 0..320u32 { let tile_pos = TilePos { x, y }; let tile_entity = commands .spawn(( TileBundle { position: tile_pos, tilemap_id: TilemapId(tilemap_entity), ..Default::default() }, LastUpdate::default(), )) .id(); tile_storage.set(&tile_pos, tile_entity); } } let tile_size = TilemapTileSize { x: 16.0, y: 16.0 }; let grid_size = tile_size.into(); let map_type = TilemapType::default(); commands.entity(tilemap_entity).insert(TilemapBundle { grid_size, map_type, size: map_size, storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() }); } #[derive(Default, Component)] struct LastUpdate { value: f64, } // In this example it's better not to use the default `MapQuery` SystemParam as // it's faster to do it this way: fn random(time: ResMut