Loader
How work the loader to load and store resources files
The Loader
class is an essential component in your game's ECS (Entity-Component-System) architecture.
It is responsible for efficiently loading, unloading, and managing game textures, making it an integral part of your game's resource management system.
The Loader
class simplifies the resource management process by centralizing the loading and unloading of textures. It enhances the efficiency and maintainability of your game's ECS system by providing easy access to game assets.
Constructors and Destructors
Constructor
The Loader
class has a default constructor that initializes the loader.
Destructor
The destructor for Loader
is responsible for cleaning up any resources it has loaded.
Enumerations
The toLoad
enumeration represents the various types of resources that the loader can handle. It includes:
ParallaxFirstbkg
andParallaxSecondbkg
for parallax background textures.Player_move1
,Player_move2
,Player_move3
, andPlayer_move4
for player character movement animations.Missile
for missile textures.Monster1
for monster character textures.
Methods
This method allows you to load a texture from a file and associate it with a specific resource type.
path
: The file path to the texture you want to load.type
: The type of resource you are loading.
Use this method to unload a previously loaded texture for a specific resource type.
type
: The type of resource you want to unload.
Retrieve a loaded texture associated with a particular resource type. This method returns a reference to the texture.
type
: The type of resource for which you want to retrieve the texture.
Data Structures
The Loader
class uses an std::unordered_map
to efficiently store and manage the loaded textures. The textures are stored as shared pointers to sf::Texture
objects, ensuring that they are properly managed and unallocated when necessary.
Error Handling
The getTexture
method performs error handling by throwing a client::MyError
exception if the requested texture is not found. This ensures that you receive an appropriate error message when attempting to retrieve a missing texture.
You will also find some method for the font
As you may see through their names, theses methods can be used to load a font, unload it or even got it.
The biggest par of this class is this enum
This enum contains all the things that the game has to load before to start a game. So, he load all of these things when the program's launch.
Last updated