Examples
These examples demonstrate the main features of Bevy and how to use them.
To run an example, use the command cargo run --example <Example>
, and add the option --features x11
or --features wayland
to force the example to run on a specific window compositor, e.g.
cargo run --features wayland --example hello_world
Hello, World!
Example |
Main |
Description |
hello_world |
hello_world.rs |
Runs a minimal example that outputs "hello world" |
2D Rendering
3D Rendering
Example |
File |
Description |
load_gltf |
3d/load_gltf.rs |
Loads and renders a gltf file as a scene |
msaa |
3d/msaa.rs |
Configures MSAA (Multi-Sample Anti-Aliasing) for smoother edges |
parenting |
3d/parenting.rs |
Demonstrates parent->child relationships and relative transformations |
3d_scene |
3d/3d_scene.rs |
Simple 3D scene with basic shapes and lighting |
spawner |
3d/spawner.rs |
Renders a large number of cubes with changing position and material |
texture |
3d/texture.rs |
Shows configuration of texture materials |
z_sort_debug |
3d/z_sort_debug.rs |
Visualizes camera Z-ordering |
Application
Assets
Audio
Example |
File |
Description |
audio |
audio/audio.rs |
Shows how to load and play an audio file |
Diagnostics
ECS (Entity Component System)
Games
Example |
File |
Description |
breakout |
game/breakout.rs |
An implementation of the classic game "Breakout" |
Input
Scene
Example |
File |
Description |
scene |
scene/scene.rs |
Demonstrates loading from and saving scenes to files |
properties |
scene/properties.rs |
Demonstrates Properties (similar to reflections in other languages) in Bevy |
Shaders
Example |
File |
Description |
shader_custom_material |
shader/shader_custom_material.rs |
Illustrates creating a custom material and a shader that uses it |
shader_defs |
shader/shader_defs.rs |
Demonstrates creating a custom material that uses "shaders defs" (a tool to selectively toggle parts of a shader) |
UI (User Interface)
Example |
File |
Description |
button |
ui/button.rs |
Illustrates creating and updating a button |
text |
ui/text.rs |
Illustrates creating and updating text |
font_atlas_debug |
ui/font_atlas_debug.rs |
Illustrates how FontAtlases are populated (used to optimize text rendering internally) |
ui |
ui/ui.rs |
Illustrates various features of Bevy UI |
Window
WASM
pre-req
$ rustup target add wasm32-unknown-unknown
$ cargo install wasm-bindgen-cli
build & run
Following is an example for headless_wasm
. For other examples in wasm/ directory,
change the headless_wasm
in the following commands and edit examples/wasm/index.html
to point to the correct .js
file.
$ cargo build --example headless_wasm --target wasm32-unknown-unknown --no-default-features
$ wasm-bindgen --out-dir examples/wasm/target --target web target/wasm32-unknown-unknown/debug/examples/headless_wasm.wasm
Then serve examples/wasm
dir to browser. i.e.
$ basic-http-server examples/wasm