How compilation system work on Android until the asset management system is resolved?

Introduction

Well, this is a tip on how to compile on Android, how it works, and things to consider if you do so.

Sound Management

Many users have asked the same question in different communities, forums, and groups, and even personal chats, is how to add sounds into the game. Therefore, here it goes:

  1. Create the pack file. I'll not be going detail on how to create pack files, though.
  2. Instead of adding pack file alongside the application, embed it directly to the software. #pragma embed your_pack.dat
  3. Instead of opening the pack file with its name, use the star (*) character to do so. pack.open("*", PACK_OPEN_MODE_READ);

That's it!

You can also do something, for example to embed the sound if it is Android, otherwise open as pack file itself, in which case the pack file must exist alongside the compiled application.

First, at the top of the main script:

#if android
#pragma embed packname.dat
string soundloc = "*";
#endif
#if_not android
#pragma asset packname.dat
string soundloc = "packname.dat";
#endif

And then you can use the soundloc variable to open the pack, no need to check the OS again during the runtime:

pack p;
p.open(soundloc, PACK_OPEN_MODE_READ);
1 Like