Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/examples/2d/transparency_2d.rs
6592 views
1
//! Demonstrates how to use transparency in 2D.
2
//! Shows 3 bevy logos on top of each other, each with a different amount of transparency.
3
4
use bevy::prelude::*;
5
6
fn main() {
7
App::new()
8
.add_plugins(DefaultPlugins)
9
.add_systems(Startup, setup)
10
.run();
11
}
12
13
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
14
commands.spawn(Camera2d);
15
16
let sprite_handle = asset_server.load("branding/icon.png");
17
18
commands.spawn((
19
Sprite::from_image(sprite_handle.clone()),
20
Transform::from_xyz(-100.0, 0.0, 0.0),
21
));
22
commands.spawn((
23
Sprite {
24
image: sprite_handle.clone(),
25
// Alpha channel of the color controls transparency.
26
color: Color::srgba(0.0, 0.0, 1.0, 0.7),
27
..default()
28
},
29
Transform::from_xyz(0.0, 0.0, 0.1),
30
));
31
commands.spawn((
32
Sprite {
33
image: sprite_handle,
34
color: Color::srgba(0.0, 1.0, 0.0, 0.3),
35
..default()
36
},
37
Transform::from_xyz(100.0, 0.0, 0.2),
38
));
39
}
40
41