我希望能够使用Bevy读取和设置窗口设置。我尝试用一个基本的系统来实现:
fn test_system(mut win_desc: ResMut<WindowDescriptor>) {
win_desc.title = "test".to_string();
println!("{}",win_desc.title);
}虽然这是有效的(部分),但它只给你原始的设置,它不允许任何更改。在本例中,标题不会改变,但标题的显示会改变。在另一个示例中,如果要打印win_desc.width,则不会反映更改窗口大小(在运行时手动更改)。
发布于 2020-08-31 15:07:55
目前,WindowDescriptor仅在窗口创建期间使用,以后不会更新
为了在窗口调整大小时得到通知,我使用这个系统:
fn resize_notificator(resize_event: Res<Events<WindowResized>>) {
let mut reader = resize_event.get_reader();
for e in reader.iter(&resize_event) {
println!("width = {} height = {}", e.width, e.height);
}
}其他有用的事件可以在https://github.com/bevyengine/bevy/blob/master/crates/bevy_window/src/event.rs上找到
发布于 2020-12-07 11:05:49
在bevy GitHub存储库中提供了一个很好的使用窗口的示例:https://github.com/bevyengine/bevy/blob/master/examples/window/window_settings.rs
对于您的读/写窗口大小的情况:
fn window_resize_system(mut windows: ResMut<Windows>) {
let window = windows.get_primary_mut().unwrap();
println!("Window size was: {},{}", window.width(), window.height());
window.set_resolution(1280, 720);
}正如zyrg提到的,您还可以监听窗口事件。
https://stackoverflow.com/questions/63652767
复制相似问题