Working with SFML 1.6 and when I display a block a text to the screen, it flickers everytime the window reads an event (like moving my mouse). When I say flicker, I mean ghosts of a string a piecing together appear at the end. I know it has to be the string giving me problems but I'm not sure why.
If I draw a line of text from code, there's no ghosting. If I draw my compiled string (pieced together from a string vector) I get flickers. This is even if I use string::assign and make a copy to a different variable.
This is probably a rookie problem but I'm not really sure what went wrong. I started from using tutorials and wiki code:
http://www.gamefromscratch.com/page/Game-from-Scratch-CPP-Edition-Part-2.aspxhttp://www.gamefromscratch.com/page/Game-From-Scratch-CPP-Edition-Part-3.aspxhttps://github.com/SFML/SFML/wiki/Source%3A-Settings-ParserEDIT: If you need a text file to load, any block of text under 1000 characters will do:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent varius, dolor ac viverra vulputate, purus turpis molestie augue, id iaculis mauris nulla a enim. Donec augue nibh, cursus a pharetra sit amet, elementum non leo. Phasellus leo felis, feugiat in mollis vitae, aliquam ut dui. Suspendisse suscipit est sapien, eget aliquet nisl. Vestibulum sed mauris diam. Aliquam erat volutpat.
Praesent lectus nunc, aliquet ut vulputate ac, eleifend sed velit. Morbi sed metus non leo molestie rhoncus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Ut id purus metus, non sollicitudin dolor. Mauris sapien sem, viverra ut lobortis id, dapibus eget neque. Fusce eu arcu sapien. Mauris non metus nisi. Mauris commodo massa in nibh viverra euismod vel et nulla. Cras lacinia nisl scelerisque tortor scelerisque ac euismod libero suscipit. Vestibulum quis ornare leo. Phasellus non metus vitae eros pharetra interdum bibendum a mi.
Code from the class I use to wrap the text (reads a text file, makes a vector of strings, builds a single string from the vector to output).
std::string TextParser::Wrap(std::string line)
{
std::string buffer, word;
std::vector<std::string> textWrap;
std::string::iterator s_it;
std::vector<std::string>::iterator v_it, pushtxt;
unsigned int wrapLength = 80;
for(s_it = line.begin(); s_it < line.end(); s_it++)
{
if((*s_it) != ' ' && (*s_it) != '\n')
{
word += (*s_it);
}
else if ((*s_it) == '\n')
{
while((*s_it) == '\n')
{
word.append(1, *s_it);
s_it++;
}
s_it--;
buffer += word;
word.clear();
textWrap.push_back(buffer);
buffer.clear();
}
else
{
if(buffer.length() + word.length() > wrapLength)
{
buffer.append(1, '\n');
textWrap.push_back(buffer);
buffer.clear();
}
buffer += word;
buffer.append(1, ' ');
word.clear();
}
}
//clear out the last bit
textWrap.push_back(buffer);
std::string output;
for ( pushtxt=textWrap.begin() ; pushtxt < textWrap.end(); pushtxt++ )
{
output += *pushtxt;
}
return output;
}
And here's the code I use to draw the text to the screen:
void Game::GameLoop()
{
switch(_gameState)
{
case Game::ShowingMenu:
{
ShowMenu();
break;
}
case Game::ShowingSplash:
{
ShowSplashScreen();
break;
}
case Game::Playing:
{
TextParser introText("text/intro.txt");
introText.Read();
std::string outputString;
outputString.assign(introText.Wrap(introText.getRaw()));
sf::Font cutText;
//Load font from file
if(!cutText.LoadFromFile("font/PTC55F.ttf"))
{
// Error...
}
sf::String screenText(outputString, cutText, 18);
screenText.SetColor(sf::Color(255,255,255));
screenText.Move(300.f, 160.f);
sf::Event currentEvent;
while(_mainWindow.GetEvent(currentEvent))
{
if(currentEvent.Type == sf::Event::Closed)
{
_gameState = Game::Exiting;
}
if(currentEvent.Type == sf::Event::KeyPressed)
{
if(currentEvent.Key.Code == sf::Key::Escape)
{
ShowMenu();
}
}
_mainWindow.Clear(sf::Color(0,0,0));
_mainWindow.Draw(screenText);
_mainWindow.Display();
}
break;
}
}
}
I don't have my webserver up so I can't just upload the entire project. However, if you want to see anything else just let me know. Finally got the text wrap "working" and displaying the text does this. I have no idea where to begin to solve it.