#Can't get tilemap working. Was "How to add render feature?"

1 messages · Page 1 of 1 (latest)

arctic ingot
#

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()
        });
    }
}
```~~
fossil plaza
#

The feature is render not bevy/render

#

However that’s a default feature so it should work by default unless you’ve disabled default features 🤔

arctic ingot
#

how might i've gone about doing that...? i definitely didn't go out of my way to do that. i'm just gonna push then i'll link the repo

arctic ingot
#

Maybe it's all outdated

fossil plaza
#

Are you trying to run the example? Or is this in your own crate?

arctic ingot
#

This is my own game I'm trying to make

#

Trying to make a startup system to create a tilemap based on the example

fossil plaza
#

Do you have a repo?

arctic ingot
#

Yeah, the one I just linked

#

oh but i haven't pushed my broken changes

fossil plaza
#

I don’t see bevy_ecs_tilemap one your code

#

Oh haha

#

Could you share your updated Cargo.toml?

arctic ingot
#

pushed the commit

fossil plaza
#

Oh I see the issue

arctic ingot
#

oh, systems/startup.rs for the attempt

#

oh?

fossil plaza
#

You’re using the features from bevy_ecs_tilemap

#

You can only use your own features in cfg iirc

arctic ingot
#

So the features are specific to the example?

fossil plaza
#

Specific to the crate

#

Are you trying to allow your code to optionally run with those features disabled?

arctic ingot
#

I guess I was just following along with what I saw heh
Should've asked what it meant

I don't want rendering the tilemap to be optional

fossil plaza
#

Gotcha

arctic ingot
#

I should remove the cfg's i assume

fossil plaza
#

Then yeah just remove those attributes

arctic ingot
#

OK

#

Still don't see the tilemap though
I guess that's something else

fossil plaza
#

The features required by that example (render enabled, atlas disabled) are already the default for that crate

arctic ingot
#

And just to clarify, render and atlas are specific to bevy_ecs_tilemap, right?

fossil plaza
#

Yep

arctic ingot
#

features are like #ifdef BLAH where BLAH is set by the compiler options for C++ or assembly, isnt it

fossil plaza
#

Pretty similar yeah

arctic ingot
#

mhm okay

#

well, i guess i should make a new thread for the fact that i dont see anything, if i cant figure it out.
Thanks!

#

...post, not thread

fossil plaza
#

Yeah that’s likely a different issue

arctic ingot
#

Can't get tilemap working. Was "How to add render feature?"

#

Actually I think it would be odd to post nearly identical help text twice

#

I removed the cfg lines

#

But I just see nothing

#

I'm using the tiles.png from the crate's repo

#

i un-pushed the commit (force push) but i guess i could put it back again if there isnt' someone who can figure it out by looknig at the posted code