Add initial plugin creating a 256x256 texture
This commit is contained in:
parent
8969420824
commit
d40e05da3a
|
@ -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()
|
||||||
|
});
|
||||||
|
}
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in New Issue