Replies: 1 comment 1 reply
-
Generally people use Tag components to query tiles, but I think an A more purposeful tag component might look something like: struct WaterTile;
struct GroundTile;
// Spawn all water tiles..
let tile_entity = commands
.spawn(TileBundle {
position: tile_pos,
tilemap_id: TilemapId(tilemap_entity),
..Default::default()
})
.insert(WaterTile)
.id(); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I'm a total noob to Bevy and bevy_ecs_tilemap so I'm probably just really naive about the right pattern to use. So apologies in advance for that.
I'm playing around making a simple game with a hex map and where I want to place buildings on tiles. I've got some basics working like a simple tile map and clicking on a tile adds a building entity that holds a TilePos for the tile it "belongs" to. But I can already see that might not scale well when I have a lot of buildings of different types on tiles etc.
I think I'd be better to either add building components to tile entities directly or to at least add them as children or similar.
But, it seems that querying to get individual tiles is somewhat unclear to me. I see where tiles are added to the world (in my case,. in the
fill_tilemap
function. But they are added as a bundle of stuff and therefore there's not an obvious way for me to do a query that's only going to get back tiles.Is this where people sometimes add "marker" components to entities, to make it easier to query for them?
For example, would it be good to add something like an
is_tile: IsTile
component to that bundle so there's a unit struct called `IsTile¬ we could use in our queries to helpfully find tiles?Then I could do something like:
Query<(Entity, &TilePos>, (With<IsTile>,)>
and know that I'm not getting anything other than tiles back?Or, am I completely missing how ECS systems are supposed to work and there's a better way?
TIA
Beta Was this translation helpful? Give feedback.
All reactions