Drawing the HUD, and the home and level up screens
All the code from the next three code blocks goes in the drawing phase of our game loop. All we need to do is to draw the appropriate Text
objects during the appropriate states in the draw section of the main game loop.
In the PLAYING
state, add the following highlighted code:
//Draw the crosshair
window.draw(spriteCrosshair);
// Switch to the HUD view
window.setView(hudView);
// Draw all the HUD elements
window.draw(spriteAmmoIcon);
window.draw(ammoText);
window.draw(scoreText);
window.draw(hiScoreText);
window.draw(healthBar);
window.draw(waveNumberText);
window.draw(zombiesRemainingText);
}
if (state == State::LEVELING_UP)
{
}
The vital thing to notice in the previous block of code is that we switch views to the HUD view. This causes everything to be drawn at the precise screen positions we gave...