3
« on: September 25, 2010, 03:37:34 am »
Hey again, this time I really came across something I can't figure out.
I wrote a text display function so that the text will have a type writer effect (1 letter displayed at a time until the whole string is displayed).
void writer (string s, int xpos, int ypos) //s is the whole string planned to be displayed, xpos and ypos are the position coordinates of the string.
{
vector<char> vechars; //vector to store the letters from the string one by one.
string text(s.size(), ' '); //a second string to be put into sf::String with the portion of the original string taken from the vector to be displayed.
for (int i = 0; i <= s.size(); ++i)
{
vechars.push_back(s[i]); //put a letter from s to the vector
for (int j = 0; j <= vechars.size(); ++j)
{
text[i] = vechars[i]; // map all the chars from the vector to the new string.
}
sf::String temptext(text, MyFont, 25);// put the new string into SFML to be displayed.
temptext.Move(xpos, ypos);
App.Draw(temptext);
for (int w = 0; w < 10; ++w)
{
App.Display(); // display it for 10 frames per letter so the effect lasts longer.
}
}
}
Supposedly, this code should work, and it does, everything does run. however, when the letters are being displayed one by one, the entire string is constantly very jittery and flickers a lot. At first I assumed that this was before I did not do App.Clear(); before every frame, but then I realized I can't really do it because then I would have to pass EVERYTHING (background images, other images, etc) to the function to even get it to run.
Taking out the for loop for the 20 frame per letter display makes it not jittery anymore, but the font looks a lot fatter than it should, making it impossible to be read. I assume this is a problem with not properly clearing the screen every time app.display is called, but I don't really know how I can clear the screen if there's already background images which can't really be passed into the function.