The DefaultPlugins is a set of plugins. One of the plugins is the WindowPlugin, which defines an interface for windows. To initialize a window different from the default one, we can change the WindowPlugin by the set method of DefaultPlugins.
use bevy::app::PluginGroup;
use bevy::utils::default;
use bevy::window::{Window, WindowPlugin, WindowPosition};
use bevy::{app::App, DefaultPlugins};
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "A Bevy App".into(),
position: WindowPosition::At((0, 0).into()),
resolution: (200., 100.).into(),
..default()
}),
..default()
}))
.run();
}
We set the primary_window field of the WindowPlugin by providing it with the Window struct and describing the appearance of our window.
The default function is a syntax sugar for Default::default in Bevy.
Result:
➡️ Next: Changing The Window After Initialization
📘 Back: Table of contents