Font management

Before we start to build the structure of our graphical user interface, we need a way to manage and handle the loading and unloading of fonts automatically, just like we did with textures. The effort we put into the resource manager written back in Chapter 6, Set It in Motion! – Animating and Moving around Your World, is about to pay off. In order to manage fonts, all we need to do is create a FontManager.h file and write the following code:

class FontManager : public ResourceManager<FontManager, sf::Font>{ public: FontManager() : ResourceManager("fonts.cfg"){} sf::Font* Load(const std::string& l_path){ sf::Font* font = new sf::Font(); if (!font->loadFromFile( Utils::GetWorkingDirectory() + l_path)) { delete font; font = nullptr; ...

Get SFML Game Development By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.