0

I am attempting to learn to use Rust and Amethyst. As a starter project, I am creating a simple text adventure. I am attempting to create a "welcome" initialization page with a background image located at "/assets/images/Background.png". Without the resources_dir logic in the display.ron file provided, the code compiles without error, but obviously does not display the image. I've tried almost every permutation of the resources_dir logic, and all result in the same error referring to the logic:

Running `c:\Rust\First_Test\target\debug\First_Test.exe`
Error: Error { inner: Inner { source: None, backtrace: None, error: Parser(Parser(ExpectedMapEnd, Position { col: 32, line: 12 })) } }
error: process didn't exit successfully: `c:\Rust\First_Test\target\debug\First_Test.exe` (exit code: 1)

This is the display.ron:

(
    title: "Pick Up Your Mother",
    window: {
        title: "Pick Up Your Mother",
        fullscreen: false,
        maximized: false,
        borderless: false,
        dimensions: Some((1024, 1024)),
    },
    renderer: {
        fullscreen: false,
        resources_dir: "assets".to_string(),
    }
)

This is my main.rs file:

use amethyst::{
    assets::{AssetStorage, Handle, Loader},
    core::{
        math::Vector3,
        transform::{Transform, TransformBundle},
    },
    ecs::prelude::World,
    prelude::*,
    renderer::{
        formats::texture::ImageFormat,
        plugins::{RenderFlat2D, RenderToWindow},
        sprite::{SpriteRender, SpriteSheet},
        types::{DefaultBackend, Texture},
        RenderingBundle,
    },
    utils::application_root_dir,
};

struct GameState;

impl SimpleState for GameState {}

fn main() -> amethyst::Result<()> {
    amethyst::start_logger(Default::default());
    let app_root = application_root_dir()?;
    let display_config_path = app_root.join("config").join("display.ron");
    let assets_dir = app_root.join("assets");

    let game_data = GameDataBuilder::default()
        .with_bundle(
            RenderingBundle::<DefaultBackend>::new()
                .with_plugin(RenderToWindow::from_config_path(display_config_path)?.with_clear([0.0, 0.0, 0.0, 1.0]))
                .with_plugin(RenderFlat2D::default()),
        )?
        .with_bundle(TransformBundle::new())?;

    let mut game = Application::new(assets_dir, GameState, game_data)?;
    game.run();

    Ok(())
}

fn initialize_background(world: &mut World, spritesheet_handle: Handle<SpriteSheet>) {
    let texture_handle = load_texture(world, "/images/Background.png");
    let sprite_render = SpriteRender {
        sprite_sheet: spritesheet_handle,
        sprite_number: 0,
    };

    let mut transform = Transform::default();
    transform.set_scale(Vector3::new(10.0, 10.0, 1.0));

    world
        .create_entity()
        .with(sprite_render)
        .with(transform)
        .build();
}

fn load_texture(world: &mut World, path: &str) -> Handle<Texture> {
    let loader = world.read_resource::<Loader>();
    let texture_storage = world.read_resource::<AssetStorage<Texture>>();
    loader.load(path, ImageFormat::default(), (), &texture_storage)
}

And my cargo.toml:

[package]
name = "First_Test"
version = "0.1.0"
edition = "2021"

[dependencies]
amethyst = { version = "0.15.3", features = ["vulkan"] }

I'm aware that there are several unused and improperly labeled function, but these are not causing the compiling error I am receiving. I'm also aware of my title case issue. If I remove the resources_dir logic, the code compiles. Added in any way, it returns that error. What have I missed?

I've tried essentially every single permutation of the resources_dir logic that I can imagine. I have moved the folders around the directory as well, to no avail.

Anders Evensen
  • 579
  • 5
  • 15

0 Answers0