diff --git a/examples/Assets/main.cpp b/examples/Assets/main.cpp new file mode 100644 index 000000000..edf75fdb0 --- /dev/null +++ b/examples/Assets/main.cpp @@ -0,0 +1,39 @@ +#include +#include +#include + +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 app(argc, argv); + + auto& windowing = app.AddComponent(); + auto& fs = app.AddComponent(); + fs.Mount("game:/", resourceDir); + + auto& catalog = app.AddComponent(); + catalog.AddFolder("game:/"); + + // Load an asset from its path + Nz::Asset music = Nz::Asset::LoadFromFile("game:/examples/Audio/file_example_MP3_700KB.nzasset"); + + // or by its name + music = catalog.Load("file_example_MP3_700KB"); + music->Play(); + + Nz::Asset sound = catalog.Load("examples/Audio/siren"); + sound->Play(); + + app.AddUpdaterFunc([&] + { + if (!music->IsPlaying()) + app.Quit(); + + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + }); + + return app.Run(); +} diff --git a/examples/Assets/xmake.lua b/examples/Assets/xmake.lua new file mode 100644 index 000000000..4071bd3dd --- /dev/null +++ b/examples/Assets/xmake.lua @@ -0,0 +1,3 @@ +target("Assets") + add_deps("NazaraGraphics", "NazaraAudio") + add_files("main.cpp")