Bevy

https://bevy.org/
https://www.rustadventure.dev/flappy-bird/bevy-0.18/how-to-start-a-new-bevy-game (Notes below)

Installed Bevy CLI https://github.com/TheBevyFlock/bevy_cli

Component: struct
System: function

bevy new -t desired_template name

Every frame Bevy runs systems in groups called schedules but not all schedules run every frame.

Systems can be added to schedules. Some schedules run every frame, others do not (such as Startup)

use bevy::prelude::*;

fn main() -> AppExit {    
	App::new()        
		.add_plugins(DefaultPlugins)
		.add_systems(Startup, startup)
		.run()
}
	
fn startup(mut commands: Commands) {
	commands.spawn(Camera2d);
}

We can add systems to a Schedule by taking advantage of the builder APIs on the App type. App::add_systems allows us to specify one or many systems to add to a given schedule. In this case we’re adding a system named startup to the Startup schedule.

System can be a regular function, which is how we define our startup system. These Systems can be added to any number of schedules, which controls when they’ll run within each frame.

Commands

Commands is one of the injectable params, which we call SystemParams. We can query the state of the world and many more using these SystemParams.
...
We queried for the Entity itself because Commands has a nifty function called Commands::entity which lets us get access to an EntityCommands for a given Entity. This is the same set of actions we can take when spawning a new Entity, which means it allows us to insert Components and other operations.
https://docs.rs/bevy/0.18.0/bevy/ecs/prelude/struct.Commands.html#method.entity

Schedules

Common schedules (Main)
...

Assets

Loading the file will require using the AssetServer. The AssetServer is stored in a Resource that we can ask for in our Systems.
We’ll use the AssetServer::load function to load the bevy-bird png. This function will not block our program while loading, but it will give us a Handle to the asset that we can use with the Sprite. A Handle is an id that we can use to identify specific assets after loading them.

Required Components

Components can specify Required Components. If some Component A requires Component B, then when A is inserted, B will also be initialized and inserted (if it was not manually specified).
https://docs.rs/bevy/0.18.0/bevy/ecs/component/trait.Component.html#required-components

"Default"  the Default implementation for an f32 is 0.0

#[derive(Component, Default)]
struct Velocity(f32);

Query

system parameter that provides selective access to the Component data stored in a World.

Queries enable systems to access entity identifiers and components without requiring direct access to the World. Its iterators and getter methods return query items, which are types containing data related to an entity.

Query is a generic data structure that accepts two type parameters:

fn gravity(    
	mut transforms: Query<(        
		&mut Transform,        
		&mut Velocity,        
		&Gravity,    
	)>,    
	time: Res<Time>,
) {
	for (mut transform, mut velocity, gravity) in
		&mut transforms
	{
		velocity.0 -= gravity.0 * time.delta_secs();   
		transform.translation.y +=            
			velocity.0 * time.delta_secs();    
	}
}

Time

Each frame, using Res<Time> gives us access to how much time has passed via the delta_secs function (see example in Query).
...
We also need to add this system to our App, for which we have two options. The system can run in the Update schedule or the FixedUpdate schedule. Either will work at first, especially if you’re only ever running on a single computer and a single monitor, but the delta time in Update is dependent on the framerate while FixedUpdate will have a consistent delta time. Generally speaking, rendering logic goes in Update while gameplay logic goes in FixedUpdate as a result, which helps to ensure consistent behavior across framerates and devices.

Controls

App::new().add_systems(Update, controls).run()

Visibility of Entity with Children

It is also notable that if you forget Visibility::Visible on the root Entity you will see warnings! This is because we have children with Sprites which need to be rendered, but our root element doesn’t have anything like that. The visibility progpagates down the hierarchy, so a missing Visibility component on a node in the middle of the tree can cause issues!

WARN bevy_ecs::hierarchy: warning[B0004]: Entity 21v0 with the Enable the debug feature to see the name component has a parent (18v0 entity) without Enable the debug feature to see the name.

Transform

Transform represents a local position offset from the entity’s parent’s position. A GlobalTransform represents the entity’s position in global space. At the end of every frame, Transforms are accumulated through the tree of entities that exist, and those values are stored in the GlobalTransform.

We want this global position value to do our collision detection, but since the GlobalTransform is only updated at the end of the frame we have two choices: