我对 Bevy 和 Rust 还很陌生。我想加载一个 png 图像并获取它的宽度和高度。下面的代码不会打印“找到的资源...”。
fn setup( mut commands: Commands,
asset_server: Res<AssetServer>,
mut materials: ResMut<Assets<Image>>) {
let texture_handle = asset_server.load("board.png");
//materials.add(texture_handle.clone().into()); //Gives error: the trait `From<Handle<_>>` is not implemented for `bevy::prelude::Image`
commands.spawn().insert_bundle(SpriteBundle {
texture: texture_handle.clone(),
..Default::default()
}).insert(BackgroundSprite);
if let Some(image) = materials.get(texture_handle) {
print!("found resource with width and height: [{},{}]", image.texture_descriptor.size.width, image.texture_descriptor.size.height);
}
}