在Bevy游戏引擎中,将1000x1000像素的纹理分配给SpriteSheetBundle需要5秒的时间



是否有改善这种情况的方法,或者我只是使用引擎错误?我试图通过首先创建和生成低质量的背景图像来解决这个问题。

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);
}

我正在加载纹理到"Textures"像这样的资源

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),
});
}

当使用--release命令行选项编译时,它运行得更快,因为发布配置文件已经启用了优化。

见货物文件

由于性能问题是由堆栈本身而不是您的代码引起的,因此使用发布标志似乎有点激进。将以下代码行添加到您的Cargo.toml中,仅对依赖项进行优化编译,这将增加开发时的编译时间。

[profile.dev.package."*"]
opt-level = 3

最新更新