Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showing a loading screen while waiting for assets to load #89

Open
tigleym opened this issue Nov 19, 2020 · 1 comment
Open

Showing a loading screen while waiting for assets to load #89

tigleym opened this issue Nov 19, 2020 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@tigleym
Copy link
Collaborator

tigleym commented Nov 19, 2020

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.

@tigleym tigleym added the enhancement New feature or request label Nov 19, 2020
@tigleym tigleym assigned tigleym and unassigned tigleym Nov 19, 2020
@tigleym tigleym self-assigned this Dec 31, 2020
@tigleym
Copy link
Collaborator Author

tigleym commented Jan 5, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant