|
Allegro 5, Android, loading assets |
Ian Lewis
Member #15,817
December 2014
|
Hello all, I'm trying to port an A5 game I've written to Android (previous thread here https://www.allegro.cc/forums/thread/616695/1027864 - I've now got a 64 bit Windows machine) I've followed these instructions: https://github.com/liballeg/android and have code building and running, but it fails to load any assets. I've searched a fair bit, but can't seem to find: - Where I need to put the asset files so that they get included in the .apk when I build the project (The project structure has 4 directories called 'assets'....) - How I tell allegro where to find them. (I guess I need to start with one of the ALLEGRO_xxx_PATH defines, but I don't know which one. I maybe also need to call al_android_set_apk_file_interface() or possibly al_android_set_apk_fs_interface() but I don't know which, or when!) Can anyone help me with either of these issues? Cheers, Ian |
Sebastian Krzyszkowiak
Member #14,084
February 2012
|
After you call "al_android_set_apk_file_interface()", all file related functions from Allegro - http://liballeg.org/a5docs/trunk/file.html - are now using "assets" directory from your APK file. After you call "al_android_set_apk_fs_interface()", all filesystem related functions from Allegro - http://liballeg.org/a5docs/trunk/fshook.html - are now using "assets" directory from your APK file. So you call them depending on what you use in your code. I don't know anything about Android Studio, so if I were you I'd just place different stuff into those four "assets" directory and see what gets into the apk file (which you can simply unzip as regular zip file). |
Ian Lewis
Member #15,817
December 2014
|
Thanks for that. I hadn't realised I could open the .apk file. I can now see that I have assets in the 'assets' folder. Sadly, I still can't figure out how to get allegro to see them. The only function I use from either of those links is al_change_directory() but (obviously) I use al_load_bitmap(), al_load_sample() etc. a lot. From what you say, they are unaffected by al_android_set_apk_fs_interface(). When I use either al_get_current_directory() or al_get_standard_path() I get something like data/user/0/com.tootiredgames.gravstorm/files If I peek inside the apk, I see folders called assets (where my assets are) lib, META-INF, res, plus AndroidManifest.xml, and a few more files. I can't see any relationship between the path and the contents of the apk. I've tried just appending /assets to the path, but that doesn't seem to work. At the moment, it doesn't seem to make any difference whether I call al_android_set_apk_fs_interface() or not. al_load_xxx calls always return NULL. Anyone know what I should be doing to set the path so that I can load assets? Cheers, Ian. |
Sebastian Krzyszkowiak
Member #14,084
February 2012
|
Don't use al_get_current_directory nor al_get_standard_path. They are irrelevant once you switch to the apk interface. Use the relative paths. Functions like al_load_bitmap use the file interface under the hood, so you're interested mostly in al_android_set_apk_file_interface. After you call that, you should be able to just call al_load_bitmap("my_dir/my_file.png") to access a file assets/my_dir/my_file.png inside the APK. (AFAIK you should also be able to use absolute paths inside the APK in form "/my_dir/my_file.png". Basically, when using the APK interface, your assets directory becomes the root directory) |
Ian Lewis
Member #15,817
December 2014
|
Ah, thank you! Assets are now loading, and my game is running! Cheers, Ian. |
|