Trouv / bevy_ecs_ldtk

ECS-friendly ldtk plugin for bevy, leveraging bevy_ecs_tilemap
Other
641 stars 73 forks source link

Entity sprites not appearing? | Not getting TextureAtlasSprite index set correctly. #190

Closed emctague closed 1 year ago

emctague commented 1 year ago

If I make a world with an entity and make a bundle for that entity type:

#[derive(Bundle, LdtkEntity)]
pub struct PlayerBundle {
    player: Player, // Custom component for WASD controls and camera follow
    #[bundle]
    #[sprite_sheet_bundle]
    sprite_bundle: SpriteSheetBundle, // I have a sprite set for it in-editor
}

register that bundle:

.add_startup_system(startup)
.register_ldtk_entity::<PlayerBundle>("Player")

and then in my startup system, add a camera and tilemap:

    commands.spawn(Camera2dBundle {
        camera_2d: Camera2d {
            clear_color: ClearColorConfig::Custom(Color::BLACK),
        },
        projection: OrthographicProjection {
            scale: 1.0/6.0,
            ..default()
        },
        ..default()
    });
    commands.spawn(LdtkWorldBundle {
        ldtk_handle: server.load("Map.ldtk"),
        ..Default::default()
    });

Though the bundle is instantiated, I can only see the map itself, but not the spawned player entity, no matter what I do - custom sprites in the bundle, etc. change nothing. I can confirm that the entity exists, though, and my player system with simple W/A/S/D controls can move it around while the camera tries to track it. It is set to use an editor visual from the exact same tilesheet that the tiles for the tile layer use.

Something about spawning an LdtkEntity seems to cause it to be invisible - instantiating the exact same bundle from code works perfectly fine?

An edit:

It turns out the TextureAtlasSprite index is being set to zero instead of the correct value as set from LdTk.

emctague commented 1 year ago

This was a silly mistake on my part, I had missed something obvious in my own code that was overwriting the sprite index. My apologies, I thought I had checked/disabled it long before creating this issue.