forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_node.rs
More file actions
39 lines (35 loc) · 1.14 KB
/
image_node.rs
File metadata and controls
39 lines (35 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! This example illustrates the basic usage of an `ImageNode`.
//! `ImageNode` is UI Node that render an Image.
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
// Ui camera
commands.spawn(Camera2d);
commands.spawn((
// This root Node serves as a container for the ImageNode.
// In this case, it will center the item on the screen.
Node {
width: percent(100),
height: percent(100),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
// Child Nodes are added with the `children!` macro.
children![(
// Create a new `ImageNode` with the given texture.
ImageNode::new(asset_server.load("branding/icon.png")),
// Child Node control `ImageNode` size
Node {
width: Val::Px(256.),
height: Val::Px(256.),
..default()
}
)],
));
}