Im new to bevy right now and tried to add a background to my game, after i found a pretty old article in the Internet on how to do it, i tried running it, but it didnt work(if needed error message can be provided). After that i tried running the code through ChatGPT but as ChatGPT is probably to old aswell, i came here.
Here is my Program:
use bevy::prelude::*;
struct Background;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut materials: ResMut<Assets<ColorMaterial>>) {
// Load the image asset
let texture_handle = asset_server.load("assets/DungeonBG.png");
// Create a sprite with the loaded texture
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(SpriteBundle {
material: materials.add(texture_handle.into()),
..Default::default()
})
.insert(Background);
}