Accessing tiles to change textures and to add or remove components. #263
-
Hello, first off, thanks for the great plugin. I'd like some guidance on the following: I want to change textures on tiles and add and remove components easily; I'm trying to understand how to do this properly. I've looked through the examples, specifically:
I would like clarification on a few things:
From the basics example: commands
.entity(tilemap_entity)
.insert_bundle(TilemapBundle {
grid_size,
size: tilemap_size,
storage: tile_storage,
texture: TilemapTexture(texture_handle), // Here you have to pass in a texture atlas to the tilemap.
tile_size,
transform: get_centered_transform_2d(&tilemap_size, &tile_size, 0.0),
..Default::default()
}); From the accessing example: if let Ok(mut tile_texture) = tile_query.get_mut(neighbor_entity) {
tile_texture.0 = color as u32; // Here you have to change the texture by changing the texture index.
} it appears the only way to change a tile texture is to change the texture index.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Beta Was this translation helpful? Give feedback.
-
It is also possible to build a TextureAtlas at runtime via a https://docs.rs/bevy/latest/bevy/sprite/struct.TextureAtlasBuilder.html |
Beta Was this translation helpful? Give feedback.
What's meant here is that once the tile storage is inserted onto the entity it cant be accessed until a hard sync point. This means that queries will not work to access it within the same system or a parallel system. You can however use a label/after or a different system stage as those are "hard" sync points where the commands from the system are processed.
Yes and no. Internally if you are using the atlas feature the texture provided is used directly. Without the atlas feature a custom image process runs that adds the atlas textures into an array texture. …