Adding a score and a message
Now we know enough about strings, SFML Text
, and SFML Font
to go about implementing the HUD. HUD stands for heads-up display and more formally refers to a cockpit instrumentation display that doesn’t require the pilot to look down. However, video game user interfaces, especially in-game interfaces, are often referred to as a HUD because they serve the same purpose as a cockpit HUD.
The next thing we need to do is add another #include
directive to the top of the code file. As we have learned, the sstream
class adds some useful functionality for combining strings and other variable types together into a single String.
Add the line of highlighted code.
#include <sstream>
#include <SFML/Graphics.hpp>
using namespace sf;
int main()
{
Next, we will set up our SFML Text
objects: one to hold a message that we will vary to suit the state of the game and one that will hold the score and need to be regularly updated.
The next...