#Create Bundle for components with spritesheets

2 messages · Page 1 of 1 (latest)

floral sapphire
#

I have an entity type with an animated sprite.
Currently I spawn them in setup like this:

    let texture_handle = asset_server.load("hr-transport-belt.png");
    let texture_atlas = TextureAtlas::from_grid(texture_handle, ...);
    let texture_atlas_handle = texture_atlases.add(texture_atlas);

        commands
            .spawn(SpriteSheetBundle {
                texture_atlas: texture_atlas_handle.clone(),
                sprite: TextureAtlasSprite::new(animation_indecies.first()),
                transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)),
                ..default()
            })
            .insert(Position::new(0, 0))
#

But now I am trying to spawn one at the position of a left click.
I would like to use a Bundle with default values.
How would I do this?

Here is where I would spawn them:

pub fn handle_inputs(
    mut in_events: EventReader<InputEvent>,
    mut out_events: EventWriter<ModifiedEvent>,
    mut main_query: Query<(Entity, &mut Belt)>,
    other_query: Query<(Entity, &Position)>,
    commands: &mut Commands,
) {
    for event in in_events.iter() {
        match event {
            InputEvent::Create(position) => {
                todo!("Create belt at {:?}", position);
            }
            InputEvent::Delete(position) => {
                todo!("Delete belt at {:?}", position);
            }
            ...
        }
    }```