Okay I have 1 problem : http://imgur.com/Q4d8hrm
I don't want the text to display like that, I would like it to Just update in the same position every frame instead of doing what it is doing now.
This is my code (excluding the EventHandler class and stdafx.h)
Graphics.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#pragma once
class Graphics
{
public:
Graphics();
~Graphics();
void DisplayLives();
int playerLives = 200;
std::stringstream convert;
std::string dLives;
sf::Font font;
sf::Text lives;
};
You should definitely not be attempting to load a font every time this function is called. I would suggest moving the font loading into the constructor, but since you instantiate an object before the renderwindow is created, that isn't a good idea, either. (Although why this needs to be global isn't clear.)
Okay well I am unsure of the private and public differences. I have no experience with them.
I don't see how what you did in the {...} fixed my error. It works perfectly now, I'll just have to create my function to change the lives and see if it still works
Sorry I wasn't quite clear with that hahaha, you fixed it. Thanks for that I was just wondering how. Like what did you do that changed, how did putting the ostringstream inside the loop fix my problem?
In the first version of the code there is one ostringstream object that persists until main ends. So, in each iteration of the loop you add stuff to what is already existing in the ostringstream's buffer.
In the second, one ostringstream is constructed and destroyed each iteration of the for loop.