O'Reilly logo

SFML Game Development By Example by Raimondas Pupius

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required