#Adding Background

6 messages · Page 1 of 1 (latest)

simple lotus
#

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);

}

fleet kraken
#

Here's an update to date version:

use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    // Load the image asset
    // Bevy automatically loads from the assets/ folder
    let texture = asset_server.load("DungeonBG.png");

    commands.spawn(Camera2dBundle::default());

    // Create a sprite with the loaded texture

    commands.spawn(SpriteBundle {
        texture,
        ..default()
    });
}```
#

BTW I wouldn't recommend using ChatGPT for this because bevy is constantly changing, so it's outdated most of the time

fallen swan
#

Articles tend to get quickly outdated, bevy is regularly updated