Function macroquad::file::set_pc_assets_folder
source · pub fn set_pc_assets_folder(path: &str)
Expand description
There are super common project layout like this:
.
├── assets
├── └── nice_texture.png
├── src
├── └── main.rs
└── Cargo.toml
when such a project being run on desktop assets should be referenced as “assets/nice_texture.png”. While on web or android it usually is just “nice_texture.png”. The reason: on PC assets are being referenced relative to current active directory/executable path. In most IDEs its the root of the project. While on, say, android it is:
[package.metadata.android]
assets = "assets"
And therefore on android assets are referenced from the root of “assets” folder.
In the future there going to be some sort of meta-data file for PC as well.
But right now to resolve this situation and keep pathes consistent across platforms
set_pc_assets_folder("assets");
call before first load_file
/load_texture
will allow using same pathes on PC and Android.
Examples found in repository?
examples/audio.rs (line 5)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
async fn main() {
set_pc_assets_folder("examples");
let sound1 = audio::load_sound("sound.wav").await.unwrap();
let sound2 = audio::load_sound("sound2.wav").await.unwrap();
loop {
clear_background(LIGHTGRAY);
if ui::root_ui().button(None, "Play sound 1") {
warn!("play 1!");
audio::play_sound_once(&sound1);
}
if ui::root_ui().button(None, "Play sound 2") {
warn!("play 2!");
audio::play_sound_once(&sound2);
}
next_frame().await
}
}