Skip to content

Instantly share code, notes, and snippets.

@trojanfoe
Last active December 12, 2024 13:38
Show Gist options
  • Save trojanfoe/1b27e905a35a96b35830f07f0de1c99c to your computer and use it in GitHub Desktop.
Save trojanfoe/1b27e905a35a96b35830f07f0de1c99c to your computer and use it in GitHub Desktop.
Bevy starter template (0.15)
use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
use bevy::prelude::*;
fn main() {
let mut app = App::new();
app.add_plugins((
DefaultPlugins
.set(ImagePlugin::default_nearest())
.set(WindowPlugin {
primary_window: Some(Window {
title: "My Game".to_string(),
resolution: (500.0, 500.0).into(),
resizable: true,
focused: true,
..Default::default()
}),
..Default::default()
}),
LogDiagnosticsPlugin::default(),
FrameTimeDiagnosticsPlugin,
))
.add_systems(Startup, setup)
.add_systems(Update, close_on_esc);
app.run();
}
fn setup(mut commands: Commands) {
commands.spawn(Camera2d);
}
pub fn close_on_esc(
mut commands: Commands,
focused_windows: Query<(Entity, &Window)>,
input: Res<ButtonInput<KeyCode>>,
) {
for (window, focus) in focused_windows.iter() {
if !focus.focused {
continue;
}
if input.just_pressed(KeyCode::Escape) {
commands.entity(window).despawn();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment