Allegro in the file management.
Not quite understand how the location of resource files (such as pictures) is expressed?
For example: c / abc / img00.png and c / abc / img01.png
These two pictures in the same folder, but the citation is the time to write it?
c / abc
// variable initialization
// get location of
path = al_get_standard_path ( ALLEGRO_RESOURCES_PATH ); // get location of your executable
al_append_path_component ( path, "img" ); // the folder containing your images
al_set_path_filename ( path, "image.png" ); // set the image name
image = al_load_bitmap ( al_path_cstr (path, ALLEGRO_NATIVE_PATH_SEP) );
// if you have only one image you can write as well (before al_load_bitmap)
al_set_path_filename ( path, "img/image.png" );
However, the executable file location, do not need to set it?（.exe？.cpp？）
For example, I have a picture in c / abc, I need to set the file path to：
al_append_path_component (path, "c/abc");
al_set_path_filename ( path, "c/abc/image.png" );
Is that right?
I don't really know what do you mean. However:
- you need the location of exacutable if you run your executable from another location than you're currently in. Providing that you have a folder "./docs/c/games/_your_game_/_your_executable_" than if you will be in your_game folder the default location will be the same as the location of executable - "./img/_some_img_" will become "./docs/c/games/_your_game_/img/_some_img_", but if you were in ex. "games" folder your images simply won't load.
- al_set_path_filename ( path, "img/image.png" ) is kind of a trick and I cannot grant you that it will work on any supported OS.
It works simply because al_path_cstr will replace filename with directory and filename (it produces a simple char * (string)). However it is by no means recommended solution.
bb's code is what you need when the game file are stored like :
(Here's the same code he posted, formatted for line numbers)
Beginning : path is an empty path
Line 6 : path is C:\projects\mygame\mygame.exe
Line 7 : path is C:\projects\mygame\ img\mygame.exe
Line 8 : path is c:\projects\mygame\img\ image.png
Line 12 is a way to combine line 7 and 8, but it only works is path is the "root" of your game. Otherwise, it will create paths like "img/img/img"...
Thread #617282. Printed from Allegro.cc
So this is, I understand.
thank you for the help.