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.
Loader::Loader()Destructor
The destructor for Loader is responsible for cleaning up any resources it has loaded.
Loader::~Loader()Enumerations
The toLoad enumeration represents the various types of resources that the loader can handle. It includes:
ParallaxFirstbkgandParallaxSecondbkgfor parallax background textures.Player_move1,Player_move2,Player_move3, andPlayer_move4for player character movement animations.Missilefor missile textures.Monster1for monster character textures.
Methods
void loadTexture(const std::string path, toLoad type)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.
void unloadTexture(toLoad type)Use this method to unload a previously loaded texture for a specific resource type.
type: The type of resource you want to unload.
const std::shared_ptr<sf::Texture> &getTexture(toLoad type) constRetrieve 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
void loadFont(const std::string path, toLoad type);
void unloadFont(toLoad type);
const std::shared_ptr<sf::Font> &getFont(toLoad type) const;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
enum toLoad {
ParallaxFirstbkg,
ParallaxSecondbkg,
Player_move1, Player_move2, Player_move3, Player_move4,
Missile,
MissileRed,
OrangeMissile,
PurpleMissile,
GreenMissile,
Explosion1,
Monster1,
Monster2,
Monster3,
Monster4,
Boss1,
Boss2,
Boss3,
Boss4,
CreateRoomButton,
JoinRoomButton,
QuitButton,
LeaveGame,
MatchListButton,
LooserScreen,
MenuScreen,
ChatBox,
BlackPixel,
ScoreCoche,
RedPixel,
GreenPixel,
BluePixel,
CyanPixel,
YellowPixel,
PurplePixel,
WhitePixel,
Arial,
PressStart2P,
playerLifeOutline,
playerLifeContent,
Bonus,
Bomb,
Pod1,
Pod2,
Pod3,
Laser
};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