Following the basic example for bevy_ecs_tilemap (https://github.com/StarArawn/bevy_ecs_tilemap/blob/main/examples/basic.rs) and my startup system just isn't working. Using the tiles.png image from the repo.
My code:
pub fn spawn_tilemap(
mut commands: Commands,
asset_server: Res<AssetServer>,
array_texture_loader: Res<ArrayTextureLoader>
) {
let texture_handle: Handle<Image> = asset_server.load("tiles.png");
let map_size = TilemapSize {x: 32, y: 32};
let tilemap_entity = commands.spawn_empty().id();
let mut tile_storage = TileStorage::empty(map_size);
for x in 0..map_size.x {
for y in 0..map_size.y {
let tile_position = TilePos {x: x, y: y};
let tile_entity = commands.spawn(TileBundle {
position: tile_position,
tilemap_id: TilemapId(tilemap_entity),
..Default::default()
}).id();
tile_storage.set(&tile_position, 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()
});
array_texture_loader.add(TilemapArrayTexture {
texture: TilemapTexture::Single(asset_server.load("tiles.png")),
tile_size,
..Default::default()
});
}
~~I'm following the basic example for bevy_ecs_tilemap and it has this line:
#[cfg(all(not(feature = "atlas"), feature = "render"))]
which is deactivating the code below it in my case, because:
code is inactive due to #[cfg] directives: feature = "render" is disabled.
cargo run --features=bevy/render didn't work. What does all of this actually mean? Here is the code I'm taking from:
https://github.com/StarArawn/bevy_ecs_tilemap/blob/main/examples/basic.rs
And here is my relevant startup system:
pub fn spawn_tilemap(
mut commands: Commands,
asset_server: Res<AssetServer>,
#[cfg(all(not(feature = "atlas"), feature = "render"))]
array_texture_loader: Res<ArrayTextureLoader>
) {
let texture_handle: Handle<Image> = asset_server.load("tiles.png");
let map_size = TilemapSize {x: 256, y: 256};
let tilemap_entity = commands.spawn_empty().id();
let mut tile_storage = TileStorage::empty(map_size);
for x in 0..map_size.x {
for y in 0..map_size.y {
let tile_position = TilePos {x: x, y: y};
let tile_entity = commands.spawn(TileBundle {
position: tile_position,
tilemap_id: TilemapId(tilemap_entity),
..Default::default()
}).id();
tile_storage.set(&tile_position, tile_entity);
}
}
let tile_size = TilemapTileSize {x: 8.0, y: 8.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,
..Default::default()
});
#[cfg(all(not(feature = "atlas"), feature = "render"))]
{
array_texture_loader.add(TilemapArrayTexture {
texture: TilemapTexture::Single(asset_server.load("tiles.png")),
tile_size,
..Default::default()
});
}
}
```~~