mirror of
https://github.com/bevyengine/bevy
synced 2024-12-19 01:23:09 +00:00
a9a4b069b6
# Objective - Improve reproducibility of examples ## Solution - Use seeded rng when needed - Use fixed z-ordering when needed ## Testing ```sh steps=5; echo "cpu_draw\nparallel_query\nanimated_fox\ntransparency_2d" > test cargo run -p example-showcase -- run --stop-frame 250 --screenshot-frame 100 --fixed-frame-time 0.05 --example-list test --in-ci; mv screenshots base; for prefix in `seq 0 $steps`; do echo step $prefix; cargo run -p example-showcase -- run --stop-frame 250 --screenshot-frame 100 --fixed-frame-time 0.05 --example-list test; mv screenshots $prefix-screenshots; done; mv base screenshots for prefix in `seq 0 $steps`; do echo check $prefix for file in screenshots/*/*; do echo $file; diff $file $prefix-$file; done; done; ```
36 lines
1,012 B
Rust
36 lines
1,012 B
Rust
//! Demonstrates how to use transparency in 2D.
|
|
//! Shows 3 bevy logos on top of each other, each with a different amount of transparency.
|
|
|
|
use bevy::prelude::*;
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins(DefaultPlugins)
|
|
.add_systems(Startup, setup)
|
|
.run();
|
|
}
|
|
|
|
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|
commands.spawn(Camera2d);
|
|
|
|
let sprite_handle = asset_server.load("branding/icon.png");
|
|
|
|
commands.spawn(Sprite::from_image(sprite_handle.clone()));
|
|
commands.spawn((
|
|
Sprite {
|
|
image: sprite_handle.clone(),
|
|
// Alpha channel of the color controls transparency.
|
|
color: Color::srgba(0.0, 0.0, 1.0, 0.7),
|
|
..default()
|
|
},
|
|
Transform::from_xyz(100.0, 0.0, 0.1),
|
|
));
|
|
commands.spawn((
|
|
Sprite {
|
|
image: sprite_handle,
|
|
color: Color::srgba(0.0, 1.0, 0.0, 0.3),
|
|
..default()
|
|
},
|
|
Transform::from_xyz(200.0, 0.0, 0.2),
|
|
));
|
|
}
|