Simple Counter Example - Bevy Typing CST Test
Loading…
Simple Counter Example — Bevy Code
A minimal Bevy app that displays a counter on screen and updates it with keyboard input.
use bevy::prelude::*;
struct Counter(i32);
fn main() {
App::build()
.insert_resource(WindowDescriptor {
title: "Bevy Counter".to_string(),
width: 400.0,
height: 300.0,
..Default::default()
})
.insert_resource(Counter(0))
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())
.add_system(update_counter.system())
.run();
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn_bundle(UiCameraBundle::default());
commands.spawn_bundle(TextBundle {
text: Text::with_section(
"Count: 0",
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: 40.0,
color: Color::WHITE,
},
Default::default(),
),
..Default::default()
}).insert(Counter(0));
}
fn update_counter(
keyboard_input: Res<Input<KeyCode>>,
mut query: Query<(&mut Text, &mut Counter)>
) {
for (mut text, mut counter) in query.iter_mut() {
if keyboard_input.just_pressed(KeyCode::Up) {
counter.0 += 1;
}
if keyboard_input.just_pressed(KeyCode::Down) {
counter.0 -= 1;
}
text.sections[0].value = format!("Count: {}", counter.0);
}
}Bevy Language Guide
Bevy is a modern, open-source Rust game engine designed for high-performance 2D and 3D games, with a focus on ECS architecture, modularity, and cross-platform support for desktop and web.
Primary Use Cases
- ▸Cross-platform 2D and 3D games
- ▸Rust-native game projects
- ▸Educational games and simulations
- ▸Prototypes and experimental game engines
- ▸WebAssembly and desktop deployment
Notable Features
- ▸Rust-based ECS (Entity Component System)
- ▸Modular plugin architecture
- ▸wgpu renderer for 2D/3D
- ▸Bevy UI toolkit
- ▸Asset management and hot-reloading
Origin & Creator
Bevy was created by Carter Anderson and maintained by an open-source community, emphasizing Rust-native ECS and performance-focused game development.
Industrial Note
Bevy is gaining traction in Rust-native game development, educational games, indie 2D/3D games, simulations, and hobby projects where performance and safety are priorities.