Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Moves a sprite with arrow keys.
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; }
}
}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.
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.