Skip to content

Instantly share code, notes, and snippets.

@B-Reif
Created August 2, 2021 18:25
Show Gist options
  • Save B-Reif/20f9e2e0e5256ec3707b47cf258817b0 to your computer and use it in GitHub Desktop.
Save B-Reif/20f9e2e0e5256ec3707b47cf258817b0 to your computer and use it in GitHub Desktop.
tilemap chunk bug
// During play this tilemap only renders one chunk.
fn setup_tilemap(
entity: Entity,
mut commands: Commands,
asset_server: Res<AssetServer>,
mut materials: ResMut<Assets<ColorMaterial>>,
mut map_query: MapQuery,
) {
let texture_handle = asset_server.load("textures/elevation_debug.png");
let material_handle = materials.add(ColorMaterial::texture(texture_handle));
let chunk_size = UVec2::new(16, 9);
// Create map entity and component.
let map_entity = commands.spawn().id();
let mut map = Map::new(0u16, map_entity);
// Create a new layer builder with a layer entity.
let (mut layer_builder, _) = LayerBuilder::new(
&mut commands,
LayerSettings::new(
realm_size.into(),
chunk_size,
Vec2::new(16., 16.),
Vec2::new(192.0, 16.0),
),
0u16,
0u16,
None,
);
layer_builder.set_all(TileBundle::default());
let layer_entity = map_query.build_layer(&mut commands, layer_builder, material_handle);
map.add_layer(&mut commands, 0u16, layer_entity);
commands
.entity(entity)
.insert(map)
.insert(Transform::default())
.insert(GlobalTransform::default());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment