Skip to main content
CodeSpeedTest
Languages
Start TypingJump into a test — pick any languageAdaptive TrainingUnlock chars as you master themPractice DrillsFocused sessions targeting weak spotsDaily ChallengesNew coding challenges every dayRace ModeCompete against others in real timeAI OpponentRace against an AI at your WPM levelTournamentsLive coding speed tournamentsArcade GamesZType, Overkill Survival, Glyphica & moreGamificationXP, coins, badges & quests
LeaderboardGlobal rankings for every languageCertificatesEarn verifiable Bronze / Silver / Gold certsActivityDaily streaks & historical analyticsProfileYour stats, badges & achievements
Browse Languages500+ languages with real code examplesBlogTips, guides & deep divesFree ToolsWPM calculator, typing speed report & moreFAQCommon questions answeredGetting StartedNew to CodeSpeedTest?AboutOur story & missionSupportGet help — Pro users get priorityContactGet in touch with the team
Pricing
  1. Home
  2. /
  3. Learn
  4. /
  5. Bevy

Learn Bevy - 10 Code Examples & CST Typing Practice Test

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.

View all 10 Bevy code examples →
Bevy Simple Counter ExampleBevy Moving Sprite ExampleBevy FPS Counter ExampleBevy Simple Timer ExampleBevy Mouse Position ExampleBevy Simple Animation ExampleBevy Keyboard Input ExampleBevy Spawn Moving Entity ExampleBevy Click Detection ExampleBevy Random Movement Example

Learn BEVY with Real Code Examples

Updated Nov 24, 2025

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

Basic Concepts Overview

Entities are game objects

Components are data attached to entities

Systems operate on entities/components

Resources store global state

Plugins organize functionality

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)

Building Workflow

Define entities and attach components

Write systems to manipulate entity data

Add Bevy plugins for rendering, input, and audio

Build UI using Bevy UI toolkit

Compile and run via `cargo run` for desktop or WASM

Difficulty Use Cases

Beginner: simple 2D sprite movement

Intermediate: ECS-based game logic and UI

Advanced: physics, AI, and 3D scenes

Expert: custom rendering pipelines and shaders

Studio-level: large modular Bevy projects

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

Versioning Timeline

2019 - Initial public release

2020 - ECS and rendering improvements

2021 - 0.5: UI and plugin system stabilization

2022 - 0.7: Render pipeline refactor and WASM support

2023-2025 - 0.10+ performance, 3D, and ecosystem growth

Glossary

Entity: a game object

Component: data attached to an entity

System: logic that runs on entities

Resource: global state data

Plugin: modular engine extension

Installation Setup

Install Rust toolchain

Create new project with `cargo new`

Add Bevy dependency in Cargo.toml

Run via `cargo run`

Use plugins and systems to extend functionality

Environment Setup

Install Rust toolchain

Create Bevy project via Cargo

Add dependencies and plugins

Organize entities, components, systems

Run desktop or compile for WASM

Config Files

Cargo.toml for dependencies

assets/ folder

main.rs entry point

plugin modules

shader and config files

Cli Commands

cargo new my_bevy_game

cargo run

cargo build --release

cargo install wasm-pack

cargo build --target wasm32-unknown-unknown

Internationalization

Load text via resource bundles

Custom localization plugins

Support UTF-8 fonts

Dynamic string switching

WASM-friendly text rendering

Accessibility

Keyboard navigation

Gamepad support

High-contrast text

Screen reader integration via Rust plugins

Custom input mapping

Ui Styling

Bevy UI nodes

Style components for layout

Button, Text, Image elements

Flexbox-style layout

Custom shaders for UI effects

State Management

Resources for global state

Components for entity state

SystemSet for system control

Events for messaging

Plugin-managed state

Data Management

Assets via AssetServer

Hot-reload support

Custom resources for configuration

Scene saving via serde

Component data serialized per entity

Architecture

Entity Component System (ECS) core

Plugins for modular features

Resources for global state

Systems for behavior scheduling

Render pipelines via wgpu

Rendering Model

wgpu for GPU acceleration

2D and 3D pipelines

Shader support

Batch rendering for sprites

Camera and transform systems

Architectural Patterns

ECS with entities/components

Resources for global state

System scheduling and sets

Plugin-based modularity

Event-driven messaging

Real World Architectures

2D strategy game

3D physics simulation

WebAssembly casual game

Rust-native prototype engine

Desktop action-adventure

Design Principles

Rust-native safety and performance

ECS-first architecture

Code-centric and modular

Cross-platform via Rust toolchain

Rapid iteration with hot reload

Scalability Guide

Use ECS efficiently

Minimize per-frame allocations

Pool entities/components

Modular plugins for large projects

Profile rendering and systems

Migration Guide

Update ECS API changes

Upgrade to latest wgpu renderer

Port old Bevy 0.x code to 0.10+

Refactor plugin APIs

Adjust for Rust edition changes

Performance Notes

Leverage ECS for parallelism

Use component bundles to reduce queries

Pool frequently used entities

Optimize shaders and textures

Minimize per-frame allocations

Security Notes

Validate multiplayer input server-side

Use HTTPS for asset downloads

Protect WASM builds from tampering

Avoid unsafe Rust code when possible

Use resources cautiously to prevent race conditions

Monitoring Analytics

Custom Rust logging

Performance profiling via Bevy Inspector

Event tracking for gameplay

Memory profiling

Error tracking via Rust crates

Code Quality

Organize systems in modules

Use Rust traits and generics

Document resources and components

Use Clippy for linting

Write unit tests for systems

Practical Examples

2D platformer

Top-down shooter

Roguelike with ECS

3D prototype with camera controls

WebAssembly casual game

Troubleshooting

Check system ordering in ECS

Ensure assets are loaded via AssetServer

Fix borrow-checker errors in Rust

Verify component queries match entities

Debug rendering issues via wgpu logs

Testing Guide

Run `cargo run` for desktop

Test WASM build in browser

Use logging for ECS system debugging

Profile performance with `bevy_inspector_egui`

Unit test Rust systems with `cargo test`

Deployment Options

Desktop (Windows/macOS/Linux)

WebAssembly in browser

Cross-platform via Rust compilation

Integration with Steam/Epic launchers

Embedded or experimental platforms

Tools Ecosystem

Bevy plugins (e.g., bevy_rapier for physics)

wgpu-based renderer

Bevy UI toolkit

Bevy Inspector for debugging

Asset pipelines for hot-reloading

Integrations

Rust networking libraries (Laminar, Tokio)

Bevy Rapier for physics

Audio via rodio or bevy_kira_audio

WebAssembly via wasm-pack

UI with Bevy UI plugin

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

Challenges

Create a tilemap-based game

Implement custom ECS plugin

Build UI with Bevy UI toolkit

Integrate physics via Rapier

Deploy a WASM game to browser

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

Skill Improvement Plan

Build small 2D games

Explore ECS patterns

Integrate physics and audio plugins

Learn wgpu rendering basics

Port projects to WebAssembly

Interview Questions

Explain Bevy ECS and system scheduling.

How does Bevy handle cross-platform rendering?

Difference between resources and components?

How do Bevy plugins extend functionality?

Explain entity queries and performance optimization.

Cheat Sheet

`App::build()`: initialize engine

`spawn()`: create entity

`Commands`: manipulate entities

`SystemSet`: schedule systems

`Query`: access components in systems

Books

Hands-On Rust Game Development with Bevy

Bevy Engine Game Development Cookbook

Rust ECS Game Development

Building 2D and 3D Games with Bevy

Practical Game Programming in Rust

Tutorials

Bevy Official Getting Started

Bevy Cheatbook

Bevy Engine YouTube tutorials

Rust Game Dev Working Group examples

Community Bevy examples repo

Official Docs

https://bevyengine.org/

https://docs.rs/bevy/latest/bevy/

https://github.com/bevyengine/bevy

Community Links

Bevy Discord

Bevy GitHub discussions

Reddit r/bevy

Twitter #bevyengine

Bevy Cheatbook community

Community Support

Bevy Discord

Bevy GitHub discussions

Reddit r/bevy

Bevy cheatsheets and examples

Twitter #bevyengine

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

Future Roadmap

Expanded 3D rendering features

Better plugin ecosystem

Enhanced WASM performance

Advanced UI features

Community-driven tools and assets

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

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.

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.

Code Sample Descriptions

1

Bevy Simple Counter Example

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);
    }
}

A minimal Bevy app that displays a counter on screen and updates it with keyboard input.

Let’s Try →
2

Bevy Moving Sprite Example

use bevy::prelude::*;

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup.system())
        .add_system(move_sprite.system())
        .run();
}

struct Player;

fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut materials: ResMut<Assets<ColorMaterial>>) {
    commands.spawn_bundle(OrthographicCameraBundle::new_2d());
    commands.spawn_bundle(SpriteBundle {
        material: materials.add(asset_server.load("player.png").into()),
        ..Default::default()
    }).insert(Player);
}

fn move_sprite(keyboard_input: Res<Input<KeyCode>>, mut query: Query<&mut Transform, With<Player>>) {
    for mut transform in query.iter_mut() {
        if keyboard_input.pressed(KeyCode::Left) { transform.translation.x -= 2.0; }
        if keyboard_input.pressed(KeyCode::Right) { transform.translation.x += 2.0; }
        if keyboard_input.pressed(KeyCode::Up) { transform.translation.y += 2.0; }
        if keyboard_input.pressed(KeyCode::Down) { transform.translation.y -= 2.0; }
    }
}

Moves a sprite with arrow keys.

Let’s Try →
3

Bevy FPS Counter Example

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);
    }
}

Displays FPS on screen using Bevy UI.

Let’s Try →
4

Bevy Simple Timer Example

use bevy::prelude::*;

struct TimerEvent(Timer);

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .insert_resource(TimerEvent(Timer::from_seconds(1.0, true)))
        .add_system(timer_system.system())
        .run();
}

fn timer_system(time: Res<Time>, mut timer: ResMut<TimerEvent>) {
    timer.0.tick(time.delta());
    if timer.0.finished() {
        println!("Timer triggered!");
    }
}

Runs a repeating timer event in Bevy.

Let’s Try →
5

Bevy Mouse Position Example

use bevy::prelude::*;

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_system(mouse_position.system())
        .run();
}

fn mouse_position(windows: Res<Windows>) {
    if let Some(window) = windows.get_primary() {
        if let Some(pos) = window.cursor_position() {
        println!("Mouse: x={}, y={}", pos.x, pos.y);
        }
    }
}

Prints mouse coordinates each frame.

Let’s Try →
6

Bevy Simple Animation Example

use bevy::prelude::*;

struct AnimationTimer(Timer);
struct SpriteSheet;

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup.system())
        .add_system(animate_sprite.system())
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn_bundle(OrthographicCameraBundle::new_2d());
    commands.spawn().insert(SpriteSheet).insert(AnimationTimer(Timer::from_seconds(0.1, true)));
}

fn animate_sprite(time: Res<Time>, mut query: Query<&mut AnimationTimer>) {
    for mut timer in query.iter_mut() {
        timer.0.tick(time.delta());
        if timer.0.finished() {
        println!("Frame advanced");
        }
    }
}

Plays frame-based sprite animation using a timer.

Let’s Try →
7

Bevy Keyboard Input Example

use bevy::prelude::*;

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_system(keyboard_input.system())
        .run();
}

fn keyboard_input(keyboard_input: Res<Input<KeyCode>>) {
    if keyboard_input.just_pressed(KeyCode::Space) {
        println!("Space pressed!");
    }
    if keyboard_input.just_pressed(KeyCode::Return) {
        println!("Enter pressed!");
    }
}

Detects keyboard presses and prints the key pressed.

Let’s Try →
8

Bevy Spawn Moving Entity Example

use bevy::prelude::*;

struct Mover;

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup.system())
        .add_system(move_entity.system())
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn().insert(Mover).insert(Transform::default()).insert(GlobalTransform::default());
}

fn move_entity(time: Res<Time>, mut query: Query<&mut Transform, With<Mover>>) {
    for mut transform in query.iter_mut() {
        transform.translation.x += 50.0 * time.delta_seconds();
    }
}

Spawns an entity and moves it automatically.

Let’s Try →
9

Bevy Click Detection Example

use bevy::prelude::*;

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_system(mouse_click.system())
        .run();
}

fn mouse_click(mouse_input: Res<Input<MouseButton>>) {
    if mouse_input.just_pressed(MouseButton::Left) {
        println!("Left click!");
    }
    if mouse_input.just_pressed(MouseButton::Right) {
        println!("Right click!");
    }
}

Detects mouse clicks in a Bevy window.

Let’s Try →
10

Bevy Random Movement Example

use bevy::prelude::*;
use rand::prelude::*;

struct Walker;

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup.system())
        .add_system(random_move.system())
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn().insert(Walker).insert(Transform::default()).insert(GlobalTransform::default());
}

fn random_move(mut query: Query<&mut Transform, With<Walker>>) {
    let mut rng = thread_rng();
    for mut transform in query.iter_mut() {
        transform.translation.x += rng.gen_range(-1.0..1.0);
        transform.translation.y += rng.gen_range(-1.0..1.0);
    }
}

Moves an entity randomly each frame.

Let’s Try →

Frequently Asked Questions about Bevy

What is Bevy?

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.

What are the primary use cases for Bevy?

Cross-platform 2D and 3D games. Rust-native game projects. Educational games and simulations. Prototypes and experimental game engines. WebAssembly and desktop deployment

What are the strengths of Bevy?

High-performance via Rust and ECS. Memory safety and concurrency advantages. Fast iteration with hot-reload. Cross-platform including WASM. Lightweight and modular architecture

What are the limitations of Bevy?

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

How can I practice Bevy typing speed?

CodeSpeedTest offers 10+ real Bevy code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.

Learn Other Programming Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypherGremlinPartiqlHaskellElixirFsharpView all languages →
CodeSpeedTest

Improve your coding speed, code accuracy, and programming syntax WPM with practice sessions across 500+ programming languages.

Quick Links

HomeAboutFeaturesGetting StartedLanguages

Legal & Support

Pro ⚡ PricingContactPrivacy PolicyTerms of Service

Connect

CodeSpeedTest on GitHubCodeSpeedTest on TwitterEmail CodeSpeedTest

© 2026 CodeSpeedTest. All rights reserved.