| 1 |
|
| 2 |
|
| 3 |
use bevy::{camera::visibility::RenderLayers, color::palettes::tailwind, prelude::*}; |
| 4 |
|
| 5 |
fn main() { |
| 6 |
App::new() |
| 7 |
.add_plugins(DefaultPlugins) |
| 8 |
.add_systems(Startup, setup) |
| 9 |
.add_systems(Update, rotate_sprite) |
| 10 |
.run(); |
| 11 |
} |
| 12 |
|
| 13 |
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { |
| 14 |
|
| 15 |
commands.spawn((Camera2d, IsDefaultUiCamera)); |
| 16 |
|
| 17 |
|
| 18 |
commands.spawn(( |
| 19 |
Camera2d, |
| 20 |
Camera { |
| 21 |
order: 1, |
| 22 |
|
| 23 |
clear_color: ClearColorConfig::None, |
| 24 |
..default() |
| 25 |
}, |
| 26 |
|
| 27 |
RenderLayers::layer(1), |
| 28 |
)); |
| 29 |
|
| 30 |
commands.spawn(( |
| 31 |
|
| 32 |
Node { |
| 33 |
width: percent(100), |
| 34 |
height: percent(100), |
| 35 |
display: Display::Flex, |
| 36 |
justify_content: JustifyContent::Center, |
| 37 |
align_items: AlignItems::Center, |
| 38 |
..default() |
| 39 |
}, |
| 40 |
BackgroundColor(tailwind::ROSE_400.into()), |
| 41 |
children![( |
| 42 |
Node { |
| 43 |
height: percent(30), |
| 44 |
width: percent(20), |
| 45 |
min_height: px(150), |
| 46 |
min_width: px(150), |
| 47 |
border: UiRect::all(px(2)), |
| 48 |
border_radius: BorderRadius::all(percent(25)), |
| 49 |
..default() |
| 50 |
}, |
| 51 |
BorderColor::all(Color::WHITE), |
| 52 |
)], |
| 53 |
)); |
| 54 |
|
| 55 |
|
| 56 |
commands.spawn(( |
| 57 |
Sprite { |
| 58 |
image: asset_server.load("textures/rpg/chars/sensei/sensei.png"), |
| 59 |
custom_size: Some(Vec2::new(100., 100.)), |
| 60 |
..default() |
| 61 |
}, |
| 62 |
RenderLayers::layer(1), |
| 63 |
)); |
| 64 |
} |
| 65 |
|
| 66 |
fn rotate_sprite(time: Res<Time>, mut sprite: Single<&mut Transform, With<Sprite>>) { |
| 67 |
|
| 68 |
sprite.rotation *= |
| 69 |
Quat::from_rotation_z(time.delta_secs() * 0.5) * Quat::from_rotation_y(time.delta_secs()); |
| 70 |
} |