FPS Counter Example - Bevy Typing CST Test
Loading…
FPS Counter Example — Bevy Code
Displays FPS on screen using Bevy UI.
use bevy::prelude::*;
fn main() {
App::build()
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())
.add_system(update_fps.system())
.run();
}
struct FpsText;
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn_bundle(UiCameraBundle::default());
commands.spawn_bundle(TextBundle {
text: Text::with_section(
"FPS: 0",
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: 30.0,
color: Color::WHITE,
},
Default::default(),
),
..Default::default()
}).insert(FpsText);
}
fn update_fps(time: Res<Time>, mut query: Query<&mut Text, With<FpsText>>) {
for mut text in query.iter_mut() {
text.sections[0].value = format!("FPS: {}", (1.0 / time.delta_seconds()) as i32);
}
}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.
Quick Explain
- ▸Bevy uses Rust and provides a data-driven Entity Component System (ECS) for managing game logic efficiently.
- ▸It has a built-in renderer using wgpu (WebGPU), supporting modern graphics APIs.
- ▸Bevy includes systems for input handling, audio, physics integration, asset management, and UI with its own Bevy UI toolkit.
- ▸Developers benefit from Rust’s safety, performance, and concurrency while building games that can run on Windows, macOS, Linux, and WebAssembly.
- ▸Bevy is ideal for high-performance 2D/3D games, prototypes, simulations, and experimental Rust projects.
Core Features
- ▸System scheduling for ECS
- ▸Scene management via entities/components
- ▸Input handling across platforms
- ▸Camera and transform management
- ▸Audio and asset pipelines
Learning Path
- ▸Week 1: Rust basics, ECS concepts
- ▸Week 2: Entities, components, and systems
- ▸Week 3: 2D rendering and input
- ▸Week 4: UI and audio
- ▸Week 5: 3D, plugins, and WASM deployment
Practical Examples
- ▸2D platformer
- ▸Top-down shooter
- ▸Roguelike with ECS
- ▸3D prototype with camera controls
- ▸WebAssembly casual game
Comparisons
- ▸Bevy vs Unity: Bevy is Rust-native ECS; Unity is editor-first and C#-based
- ▸Bevy vs Godot: Bevy is ECS-first and code-centric; Godot provides editor + GDScript
- ▸Bevy vs LibGDX: Bevy uses Rust; LibGDX uses Java/Kotlin
- ▸Bevy vs Phaser: Bevy for native and WASM, Phaser for HTML5 web
- ▸Bevy excels in safety, performance, and Rust-native ECS
Strengths
- ▸High-performance via Rust and ECS
- ▸Memory safety and concurrency advantages
- ▸Fast iteration with hot-reload
- ▸Cross-platform including WASM
- ▸Lightweight and modular architecture
Limitations
- ▸Smaller ecosystem than Unity/LibGDX
- ▸No official physics engine (requires plugins)
- ▸UI system still evolving
- ▸Limited built-in tools for 3D compared to AAA engines
- ▸Requires Rust knowledge
When NOT to Use
- ▸Non-Rust projects
- ▸AAA console pipelines
- ▸Teams needing visual editors
- ▸Zero-code environments
- ▸Projects requiring extensive built-in physics/UI tools
Cheat Sheet
- ▸`App::build()`: initialize engine
- ▸`spawn()`: create entity
- ▸`Commands`: manipulate entities
- ▸`SystemSet`: schedule systems
- ▸`Query`: access components in systems
FAQ
- ▸Is Bevy free?
- ▸Yes, MIT open-source license.
- ▸Does it support 3D?
- ▸Yes, fully 3D with wgpu renderer.
- ▸Can it deploy to web?
- ▸Yes, via WebAssembly.
- ▸Is Rust required?
- ▸Yes, Bevy is Rust-native.
- ▸Is it beginner-friendly?
- ▸For Rust developers; requires programming knowledge.
30-Day Skill Plan
- ▸Build small 2D games
- ▸Explore ECS patterns
- ▸Integrate physics and audio plugins
- ▸Learn wgpu rendering basics
- ▸Port projects to WebAssembly
Final Summary
- ▸Bevy is a modern, Rust-native ECS game engine for 2D and 3D.
- ▸It offers high performance, memory safety, and modular architecture.
- ▸Ideal for desktop and WebAssembly games, prototypes, and simulations.
- ▸Fully code-centric with a focus on Rust developers.
- ▸Best for teams wanting control, safety, and Rust-native tooling.
Project Structure
- ▸src/main.rs (core logic)
- ▸assets/ (images, audio, shaders)
- ▸Cargo.toml (dependencies and settings)
- ▸plugins/ (optional custom Bevy plugins)
- ▸systems/ (game logic organization)
Monetization
- ▸Desktop paid releases
- ▸WASM games with subscriptions
- ▸Integration with ad services via Rust bindings
- ▸In-game purchases via server APIs
- ▸Licensing game engines built with Bevy
Productivity Tips
- ▸Use ECS bundles to simplify entity creation
- ▸Leverage plugins for repetitive functionality
- ▸Use asset hot-reloading
- ▸Keep systems small and modular
- ▸Profile often during development
Basic Concepts
- ▸Entities are game objects
- ▸Components are data attached to entities
- ▸Systems operate on entities/components
- ▸Resources store global state
- ▸Plugins organize functionality