首页 > 解决方案 > 如何使用 Bevy 在创建后获取和设置 Window 信息?

问题描述

我希望能够使用 Bevy 读取和设置窗口设置。我试图用一个基本系统来做到这一点:

fn test_system(mut win_desc: ResMut<WindowDescriptor>) {
    win_desc.title = "test".to_string();
    println!("{}",win_desc.title);
}

虽然这有效(部分),但它只为您提供原始设置,并且根本不允许更改。在这个例子中,标题不会改变,但标题的显示会改变。在另一个示例中,如果您要打印,则不会反映更改窗口大小(在运行时手动)win_desc.width

标签: rustbevy

解决方案


目前,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找到


推荐阅读