Im trying to convert my A4 project to A5 but im having some issues...
Been searching for hours and i cant load bitmaps directly from a zip file.
Can anyone post a small example please?
What have you tried so far? You need to use the PhysFS addon to load from an archive file.
It's actually fairly simple to use with PhsyFS that's a file system addon, not a physics addon
Here's what I have (trimmed out the error checking code)
PHYSFS_init(NULL); if(!PHYSFS_mount("MyGame.zip", "/", 1)) { // do error stuff here } al_set_physfs_file_interface();
You'll need to #include <allegro5/allegro_physfs.h> as well for this.
Note, you can rename your file anything you wish, like "MyGame.dat", no need to have "zip" on there if you don't want it so obvious.
Once this is done, all file loading will be from that file. I have folders in my ZIP as well containing graphics, sounds etc... so when I load them I use something like...
ALLEGRO_BITMAP *myimage = NULL; myimage = al_load_bitmap("Graphics/MyImage.png");
...and it will load the PNG "MyImage.png" from the "Graphics" folder inside your zip file.
Important, if you wish to access a file outside of the zip you need to al_set_standard_file_interface(); first, then do your normal file access, and when you're done, use al_set_physfs_file_interface(); to switch back to your ZIP.
Another way to do this, and probably a better one, is to use:
ALLEGRO_STATE state; al_store_state(&state, ALLEGRO_STATE_NEW_FILE_INTERFACE); al_set_standard_file_interface(); // do your file access here al_restore_state(&state);
I have the following code to test.
All i get is:
Start loading backup.bmp <crash>
is the zip file actually where your program expects it?
It works!!! i forgot to add the al_init_image_addon() in the test code.
Lets see if it works in the real project now.
Good to see you got it working.
You may also want to incorporate ALLEGRO_PATH to set the working directory so that your archive can be read no matter what directory it was executed from (this comes in handy if you run the application binary from a command line from within a different directory). I used the following in one of my projects: