Resources in SFML
SFML offers classes to deal with a wide variety of resources. Often, the resource classes are not directly used to output multimedia on the periphery. Instead, there is an intermediate front-end class, which refers to the resource. In contrast to the resource class which holds all the data, the front-end class is lightweight and can be copied without severe performance impacts.
All resource classes contain member functions to load from different places. Depending on the exact resource type, there may be slight deviations. A typical method to load a resource from a file has the following signature:
bool loadFromFile(const std::string& filename);
The function parameter contains the path to the file, where the resource is stored, and the return value is a bool
, which is true
if loading was successful, and false
if it failed. It is important to check return values in order to react to possible errors, such as invalid file paths.
SFML resources also provide methods to load resources...