aircampro

ECS Rust Bevy Hot re-load

Nov 17th, 2025
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 2.08 KB | Source Code | 0 0
  1. // example of using bevy games engine with hot reloadable
  2. // $ cargo init
  3. // $ cargo add bevy
  4. //
  5. // Cargo.toml
  6. // [package]
  7. // name = "project name"
  8. // version = "0.1.0"
  9. // authors = ["XXXXX <[email protected]>"]
  10. // edition = "2025"
  11. //
  12. // [features]
  13. // hot = ["bevy_dexterous_developer/hot"]
  14. //
  15. // [dependencies]
  16. // bevy = "0.14"
  17. // bevy_dexterous_developer = "0.4"
  18.  
  19. use bevy::prelude::*;
  20. use bevy_dexterous_developer::*;
  21. const GAME_TITLE: &str = "My 2D Action Game";
  22. const DEFAULT_WINDOW_WIDTH: f32 = 1280.0;
  23. const DEFAULT_WINDOW_HEIGHT: f32 = 720.0;
  24.  
  25. reloadable_main!((initial_plugins) {
  26.     App::new()
  27.         // Specifying the window background color
  28.         .insert_resource(ClearColor(Color::rgb(0.0, 0.0, 0.0)))
  29.         // Window initial settings
  30.         .insert_resource(
  31.             WindowDescriptor {
  32.                 title: GAME_TITLE.to_string(),
  33.                 width: DEFAULT_WINDOW_WIDTH,
  34.                 height: DEFAULT_WINDOW_HEIGHT,
  35.                 resizable: false,                                   // Disable window resizing
  36.                 ..Default::default()
  37.             }
  38.         )
  39.         // All functionality of the Bevy engine is implemented as plugins.
  40.         .add_plugins(initial_plugins.initialize::<DefaultPlugins>())
  41.         .add_systems(Startup, setup)
  42.         //.add_systems(OnEnter, sound_setup)
  43.         //.add_systems(Update, (sound_system, play_sound))
  44.         //.add_systems(OnExit, sound_cleanup);
  45.         .add_systems(Update, player_movement.reloadable())
  46.         .run();
  47. });
  48.  
  49. // set-up scene
  50. fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
  51.     commands.spawn(Camera2d::default());
  52.     commands.spawn(Sprite::from_image(asset_server.load("bevy_bird_dark.png")));
  53. }
  54.  
  55. // hot re-loadable function
  56. fn player_movement(
  57.     mut query: Query<&mut Transform, With<Player>>,
  58.     time: Res<Time>,
  59. ) {
  60.     // This system will be hot reloadable.
  61.     // Movement speed and logic can be adjusted in real time.
  62.     for mut transform in query.iter_mut() {
  63.         transform.translation.x += time.delta_seconds() * 150.0;
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment