Hello, when I'm adding Color struct in ColorMaterial store and the returned Handle of this color seems do nothing inside of material argument of rendered objects. Maybe I'm doing something wrong? I will be thankful for any help.
My Code:
use bevy::prelude::*;
const GAME_TITLE: &str = "My Game";
fn main() {
App::new()
.add_plugins((
DefaultPlugins.set(
WindowPlugin {
primary_window: Some(Window {
title: GAME_TITLE.to_string(),
mode: bevy::window::WindowMode::BorderlessFullscreen,
..default()
}),
..default()
}),
))
.add_systems(Startup, setup)
.add_systems(Update, exit)
.run();
}
fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>, mut materials: ResMut<Assets<ColorMaterial>>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(
TextBundle::from_section(GAME_TITLE, TextStyle {
color: Color::srgb(255.0, 125.0, 255.0),
font_size: 60.0,
..default()
})
.with_style(Style {
position_type: PositionType::Absolute,
justify_self: JustifySelf::Center,
justify_content: JustifyContent::Center,
padding: UiRect {left: Val::Px(10.0), right: Val::Px(10.0), top: Val::Px(15.0), bottom: Val::Px(10.0)},
..default()
})
);
commands.spawn(bevy::sprite::MaterialMesh2dBundle {
mesh: bevy::sprite::Mesh2dHandle (
meshes.add(Rectangle::new(20.0, 20.0))
),
material: materials.add(Color::srgb(28.0, 176.0, 217.0)),
..default()
});
}
fn exit(keyboard: Res<ButtonInput<KeyCode>>, mut app_exit_events: ResMut<Events<bevy::app::AppExit>>) {
if keyboard.just_pressed(KeyCode::Escape) {
app_exit_events.send(bevy::app::AppExit::Success);
}
}