0

Is there a way of improving this situation or am i just using the engine wrong? I tried to go around this problem by first creating and spawning Images of the Background with lower Quality.

fn spawn_background(commands: &mut Commands, texture: Res<Textures>) {
    commands
        .spawn(SpriteSheetBundle {
            texture_atlas: texture.background_low_texture.clone(),
            transform: Transform::from_scale(Vec3::splat(10.0)),
            ..Default::default()
        })
        .with(Dummy)
        .with(Background);

    commands
        .spawn(SpriteSheetBundle {
            texture_atlas: texture.background_med_texture.clone(),
            transform: Transform::from_scale(Vec3::splat(10.0)),
            ..Default::default()
        })
        .with(Dummy)
        .with(Background);

    commands
        .spawn(SpriteSheetBundle {
            texture_atlas: texture.background_texture.clone(),
            transform: Transform::from_scale(Vec3::splat(10.0)),
            ..Default::default()
        })
        .with(Background);
}

I am loading the Texture to the "Textures" Resource like this

fn setup(
    commands: &mut Commands, 
    asset_server: Res<AssetServer>,
    mut texture_atlases: ResMut<Assets<TextureAtlas>>,
) {

    let background_texture_handle = asset_server.load("textures/background.png");
    let background_texture_atlas = TextureAtlas::from_grid(background_texture_handle, Vec2::new(1000.0, 1000.0), 1, 1);

    let background_low_texture_handle = asset_server.load("textures/background_low.png");
    let background_low_texture_atlas = TextureAtlas::from_grid(background_low_texture_handle, Vec2::new(1000.0, 1000.0), 1, 1);

    let background_med_texture_handle = asset_server.load("textures/background_med.png");
    let background_med_texture_atlas = TextureAtlas::from_grid(background_med_texture_handle, Vec2::new(1000.0, 1000.0), 1, 1);

    commands.insert_resource(Textures {
        background_texture: texture_atlases.add(background_texture_atlas),
        background_low_texture: texture_atlases.add(background_low_texture_atlas),
        background_med_texture: texture_atlases.add(background_med_texture_atlas),
    });
}
Bruno Wallner
  • 383
  • 5
  • 13

2 Answers2

2

When compiling with the --release command line option, it runs much faster as the release profile have optimization enabled.

See cargo documentation

Simson
  • 3,373
  • 2
  • 24
  • 38
Bruno Wallner
  • 383
  • 5
  • 13
0

Since the performance issues arise from bevy itself and not your code, using the release flag seems a bit radical. With the following lines added to your Cargo.toml, just the dependencies are compiled with optimization and it will increase your compile times while developing.

[profile.dev.package."*"]
opt-level = 3
sclausen
  • 1,720
  • 3
  • 15
  • 22