Add initial plugin creating a 256x256 texture

This commit is contained in:
Jarrod Doyle 2024-01-26 17:27:29 +00:00
parent 8969420824
commit d40e05da3a
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
2 changed files with 45 additions and 0 deletions

42
src/falling_sand/mod.rs Normal file
View File

@ -0,0 +1,42 @@
use bevy::{
app::{Plugin, Startup},
asset::Assets,
ecs::system::{Commands, ResMut},
math::Vec3,
prelude::*,
render::{
render_resource::{Extent3d, TextureDimension, TextureFormat},
texture::Image,
},
sprite::SpriteBundle,
transform::components::Transform,
};
pub struct FallingSandPlugin;
impl Plugin for FallingSandPlugin {
fn build(&self, app: &mut bevy::prelude::App) {
app.add_systems(Startup, setup);
}
}
fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
let image = Image::new_fill(
Extent3d {
width: 256,
height: 256,
depth_or_array_layers: 1,
},
TextureDimension::D2,
&[25, 24, 26, 255],
TextureFormat::Rgba8UnormSrgb,
);
let image_handle = images.add(image);
commands.spawn(SpriteBundle {
texture: image_handle,
transform: Transform::from_translation(Vec3::new(256., 0., 0.)),
..default()
});
}

View File

@ -1,3 +1,5 @@
mod falling_sand;
use bevy::{prelude::*, window::PresentMode}; use bevy::{prelude::*, window::PresentMode};
fn main() { fn main() {
@ -17,6 +19,7 @@ fn main() {
.set(window_plugin) .set(window_plugin)
.set(ImagePlugin::default_nearest()), .set(ImagePlugin::default_nearest()),
) )
.add_plugins(falling_sand::FallingSandPlugin)
.add_systems(Startup, setup) .add_systems(Startup, setup)
.insert_resource(ClearColor(Color::rgb_u8(45, 42, 46))) .insert_resource(ClearColor(Color::rgb_u8(45, 42, 46)))
.run(); .run();