thetawavegame/thetawave-legacy

Showing a loading screen while waiting for assets to load

tigleym opened this issue · 1 comments

The player is able to immediately interact with the game (move the spaceship around) while assets are still loading. This makes the experience seem like the game is in a broken state since nothing appears on the screen for a while.

This issue looks at implementing a "Loading" screen that waits for all initial assets to be loaded before the user can start playing.

We can probably start looking at this https://book.amethyst.rs/stable/assets/how_to_use_assets.html to get started.

There are 3 parts to this bug, which should help break down the work:

  1. Create another game state called LoadingState, which will have a ProgressCounter responsible for tracking the number of assets loaded.
pub struct LoadingState {
    // Tracks loaded assets.
    progress_counter: ProgressCounter,
}
  1. In LoadingState.on_start, we should move the initializers for various entities that are loading in textures (ie: initialize_planet) in MainGameState here. Right now, we don't pass a progress counter to Loader.load in these helpers. This where the progress counter should start tracking when these assets have finished loading.
let loader = world.read_resource::<Loader>();
let texture_storage = world.read_resource::<AssetStorage<Texture>>();
loader.load(
    format!("texture/{}", spritesheet_data.image),
    ImageFormat::default(),
    &progress_counter,    // progress counter here to track asset
    &texture_storage,
)
  1. Implement a state transition from LoadingState to MainGameState when assets are finished loading.
impl SimpleState for LoadingState {
    fn update(&mut self, _data: &mut StateData<'_, GameData<'_, '_>>) -> SimpleTrans {
        if self.progress_counter.is_complete() {
            Trans::Switch(Box::new(MainGameState::default()))
        } else {
            Trans::None
        }

    }
}

We should also create an entity to act as basic UI to indicate the game is still in LoadingState and delete it once it's finished.