Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/examples/ui/images/image_node.rs
9345 views
1
//! This example illustrates the basic usage of an `ImageNode`.
2
//! `ImageNode` is UI Node that render an Image.
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
// Ui camera
15
commands.spawn(Camera2d);
16
17
commands.spawn((
18
// This root Node serves as a container for the ImageNode.
19
// In this case, it will center the item on the screen.
20
Node {
21
width: percent(100),
22
height: percent(100),
23
align_items: AlignItems::Center,
24
justify_content: JustifyContent::Center,
25
..default()
26
},
27
// Child Nodes are added with the `children!` macro.
28
children![(
29
// Create a new `ImageNode` with the given texture.
30
ImageNode::new(asset_server.load("branding/icon.png")),
31
// Child Node control `ImageNode` size
32
Node {
33
width: px(256.),
34
height: px(256.),
35
..default()
36
}
37
)],
38
));
39
}
40
41