“Bevy version 0.10.0: 如何修复 ‘WindowDescriptor not found in this scope’ 错误?”

huangapple go评论160阅读模式
英文:

Bevy version 0.10.0: How to fix 'WindowDescriptor not found in this scope' error?

问题

Bevy版本0.10.0中的WindowDescriptor结构问题

我看到了这个教程:Bevy游戏引擎教程 - 窗口和第一个精灵(第1集),我尝试做同样的事情,但我的Bevy版本是0.10.0,而这个结构 WindowDescriptor 不起作用,我尝试了其他在Stack OverFlow上看到的方法,但到目前为止都没有成功!

我的代码如下:

use bevy::prelude::*;

pub const CLEAR: Color = Color::rgb(0.1, 0.1, 0.1);

fn main() {
    App::new()
    .insert_resource(ClearColor(CLEAR))
    .insert_resource(WindowDescriptor {
            title: "Bevy Demo".to_string(),
            width: 1600.0,
            height: 900.0,
            vsync: true,
            resizable: true,
            ..Default::default()
    })
    .add_plugins(DefaultPlugins)
    .run();
}

我的Cargo.toml看起来像这样:

[package]
name = "test-bevy-game"
version = "0.1.0"
edition = "2021"

[profile.dev]
opt-level = 1

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

[dependencies]
bevy = { version = "0.10.1", features = ["dynamic_linking"] }

调试错误是这样的:

error[E0422]: cannot find struct, variant or union type `WindowDescriptor` in this scope
 -- src\main.rs:8:22
  |
8 |     .insert_resource(WindowDescriptor {
  |                      ^^^^^^^^^^^^^^^^ not found in this scope

For more information about this error, try `rustc --explain E0422`.
error: could not compile `test-bevy-game` due to previous error

我只是不希望编译器给我关于这个的任何错误,我希望至少能够在我的代码中静态地添加ecs、vsync、width、height和title,我想知道在Bevy版本0.10.0中是否需要将版本更改为旧版本?

英文:

Problems with Bevy version 0.10.0 WindowDescriptor struct

I saw this tutorial:Bevy Game Engine Tutorial - Window and First Sprite (Ep1 and I tried to do the same thing, but my Bevy is in version 0.10.0, and this structure WindowDescriptor is not working, I've tried to do it in other ways seen here on Stack OverFlow but without success with that so far!

My code is like this:

use bevy::prelude::*;

pub const CLEAR: Color = Color::rgb(0.1, 0.1, 0.1);

fn main() {
    App::new()
    .insert_resource(ClearColor(CLEAR))
    .insert_resource(WindowDescriptor {
            title: "Bevy Demo".to_string(),
            width: 1600.0,
            height: 900.0,
            vsync: true,
            resizable: true,
            ..Default::default()
    })
    .add_plugins(DefaultPlugins)
    .run();
}

My Cargo.toml looks like this:

[package]
name = "test-bevy-game"
version = "0.1.0"
edition = "2021"

[profile.dev]
opt-level = 1

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

[dependencies]
bevy = { version = "0.10.1", features = ["dynamic_linking"] }

And the debug error is this:

error[E0422]: cannot find struct, variant or union type `WindowDescriptor` in this scope
 --> src\main.rs:8:22
  |
8 |     .insert_resource(WindowDescriptor {
  |                      ^^^^^^^^^^^^^^^^ not found in this scope

For more information about this error, try `rustc --explain E0422`.
error: could not compile `test-bevy-game` due to previous error

I just don't want the compiler to give me any errors about this, I hope I can at least add the ecs vsync, width, height, title statically in my code, I want to know if bevy in version 0.10.0 need to change the version to an older one?

答案1

得分: 2

以下是翻译好的部分:

查看Bevy的各个版本是如何操作的最佳方式(因为开发仍然相对迅速)是浏览他们大量的示例。关于窗口设置的示例可以为我们提供基础信息:

App::new()
    .add_plugins(DefaultPlugins.set(WindowPlugin {
        primary_window: Some(Window {
            title: "我是一个窗口!".into(),
            resolution: (500., 300.).into(),
            present_mode: PresentMode::AutoVsync,
            ..default()
        }),
        ..default()
    }))

因此,您可以通过创建Window并将其提供为在设置应用程序时的WindowPluginprimary_window来指定窗口的详细信息。稍后,如果需要,您可以通过Query访问Window

英文:

The best way to see how things are done in various versions of Bevy (since development is still pretty rapid) is to look through their extensive set of examples. The one for window settings can give us the basics:

App::new()
    .add_plugins(DefaultPlugins.set(WindowPlugin {
        primary_window: Some(Window {
            title: "I am a window!".into(),
            resolution: (500., 300.).into(),
            present_mode: PresentMode::AutoVsync,
            ..default()
        }),
        ..default()
    }))

So you can specify the details for the window by creating a Window and provide it as the primary_window of the WindowPlugin when setting up your app. You would then access the Window later through a Query if you need to.

huangapple
  • 本文由 发表于 2023年6月1日 02:22:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76376333.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定