Created
April 28, 2020 22:24
-
-
Save SET001/6adbaf727a7513285706a0f97bbfb20f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use amethyst::{ | |
assets::{AssetStorage, Handle, Loader, ProgressCounter}, | |
prelude::*, | |
renderer::{formats::texture::ImageFormat, SpriteSheet, SpriteSheetFormat, Texture}, | |
}; | |
use crate::menu::MenuState; | |
#[derive(Debug)] | |
pub struct HandleDesc { | |
name: String, | |
handle: Handle<Texture>, | |
} | |
pub struct LoadingState { | |
// /// Tracks loaded assets. | |
progress_counter: ProgressCounter, | |
// /// Handle to the player texture. | |
pub background_texture_handle: Option<Handle<SpriteSheet>>, | |
pub handles: Vec<HandleDesc>, | |
} | |
impl LoadingState { | |
pub fn new() -> LoadingState { | |
LoadingState { | |
progress_counter: ProgressCounter::new(), | |
background_texture_handle: None, | |
handles: Vec::new(), | |
} | |
} | |
pub fn multiLoad<T>(&mut self, paths: Vec<&str>, world: &World) -> Vec<HandleDesc> { | |
let loader = world.read_resource::<Loader>(); | |
paths | |
.iter() | |
.map(|s| HandleDesc { | |
name: s.to_string(), | |
handle: loader.load( | |
s.to_string(), | |
ImageFormat::default(), | |
&mut self.progress_counter, | |
&world.read_resource::<AssetStorage<Texture>>(), | |
), | |
}) | |
.collect() | |
} | |
} | |
impl SimpleState for LoadingState { | |
fn on_start(&mut self, data: StateData<'_, GameData<'_, '_>>) { | |
println!("loading assets..."); | |
let loader = &data.world.read_resource::<Loader>(); | |
let assets = vec![ | |
// "texture/backgrounds/space6/bright/sky.png", | |
"texture/backgrounds/space6/bright/earth.png", | |
]; | |
let handles = self.multiLoad::<Texture>(assets, &data.world); | |
} | |
fn update(&mut self, data: &mut StateData<'_, GameData<'_, '_>>) -> SimpleTrans { | |
if self.progress_counter.is_complete() { | |
Trans::Switch(Box::new(MenuState::default())) | |
} else { | |
Trans::None | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment