[Assets] Add example
This commit is contained in:
parent
5c6ea6c485
commit
1846d42401
|
|
@ -0,0 +1,39 @@
|
||||||
|
#include <Nazara/Audio.hpp>
|
||||||
|
#include <Nazara/Core.hpp>
|
||||||
|
#include <Nazara/Platform.hpp>
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
std::filesystem::path resourceDir = "assets";
|
||||||
|
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir))
|
||||||
|
resourceDir = "../.." / resourceDir;
|
||||||
|
|
||||||
|
Nz::Application<Nz::Audio> app(argc, argv);
|
||||||
|
|
||||||
|
auto& windowing = app.AddComponent<Nz::WindowingAppComponent>();
|
||||||
|
auto& fs = app.AddComponent<Nz::FilesystemAppComponent>();
|
||||||
|
fs.Mount("game:/", resourceDir);
|
||||||
|
|
||||||
|
auto& catalog = app.AddComponent<Nz::AssetCatalogAppComponent>();
|
||||||
|
catalog.AddFolder("game:/");
|
||||||
|
|
||||||
|
// Load an asset from its path
|
||||||
|
Nz::Asset<Nz::Music> music = Nz::Asset<Nz::Music>::LoadFromFile("game:/examples/Audio/file_example_MP3_700KB.nzasset");
|
||||||
|
|
||||||
|
// or by its name
|
||||||
|
music = catalog.Load<Nz::Music>("file_example_MP3_700KB");
|
||||||
|
music->Play();
|
||||||
|
|
||||||
|
Nz::Asset<Nz::Sound> sound = catalog.Load<Nz::Sound>("examples/Audio/siren");
|
||||||
|
sound->Play();
|
||||||
|
|
||||||
|
app.AddUpdaterFunc([&]
|
||||||
|
{
|
||||||
|
if (!music->IsPlaying())
|
||||||
|
app.Quit();
|
||||||
|
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
});
|
||||||
|
|
||||||
|
return app.Run();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
target("Assets")
|
||||||
|
add_deps("NazaraGraphics", "NazaraAudio")
|
||||||
|
add_files("main.cpp")
|
||||||
Loading…
Reference in New Issue