use bevy::{camera::visibility::RenderLayers, color::palettes::tailwind, prelude::*};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.add_systems(Update, rotate_sprite)
.run();
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn((Camera2d, IsDefaultUiCamera));
commands.spawn((
Camera2d,
Camera {
order: 1,
clear_color: ClearColorConfig::None,
..default()
},
RenderLayers::layer(1),
));
commands.spawn((
Node {
width: percent(100),
height: percent(100),
display: Display::Flex,
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
BackgroundColor(tailwind::ROSE_400.into()),
children![(
Node {
height: percent(30),
width: percent(20),
min_height: px(150),
min_width: px(150),
border: UiRect::all(px(2)),
..default()
},
BorderRadius::all(percent(25)),
BorderColor::all(Color::WHITE),
)],
));
commands.spawn((
Sprite {
image: asset_server.load("textures/rpg/chars/sensei/sensei.png"),
custom_size: Some(Vec2::new(100., 100.)),
..default()
},
RenderLayers::layer(1),
));
}
fn rotate_sprite(time: Res<Time>, mut sprite: Single<&mut Transform, With<Sprite>>) {
sprite.rotation *=
Quat::from_rotation_z(time.delta_secs() * 0.5) * Quat::from_rotation_y(time.delta_secs());
}