These steps will guide you through how to add text to the game:
- Create an sf::Font called headingFont so that we can load the font and then use it to display the name of the game. At the top of the screen, where we created all the variables, create the headingFont variable, as follows:
int score = 0; bool gameover = true; // Text sf::Font headingFont;
- In the init() function, right after we loaded bgSprite, load the font using the loadFromFile function:
// Create Sprite and Attach a Texture bgSprite.setTexture(bgTexture); // Load font headingFont.loadFromFile("Assets/fonts/SnackerComic.ttf");
Since we will need a font to be loaded in from the system, we have to place the font in the fonts directory, which can be found under the Assets directory. Make sure you place the font file there. The font we will be using for the heading...