Hello, I want text to scroll onto the screen. Ie. display more and more characters every time step of some given string. I also have it divided up into lines. I got the code working up the method I am using seems to be very inefficient because I am getting very low framerates. I bet it is because I am using sf::Text::SetString a lot but I am unable to think of a better solution. This is in SFML 2.0.
Here is the snippet of code I am using:
Time += float(Window.GetFrameTime())/1000.f;
int charstoshow = int(Time*CHARSPERSECOND);
for(unsigned int i=0;i<TextLines.size();++i)
{
// More or equal to the amount of chars in this line
if(charstoshow >= TextLines[i].size())
{
TextToDisplay[i].SetString(TextLines[i]);
Window.Draw(TextToDisplay[i]);
charstoshow -= TextLines[i].size();
}
// this line will run out of characters
else
{
std::stringstream ss;
for(unsigned int j=0;j<charstoshow;++j)
{
ss << TextLines[i][j];
}
string temp;
ss >> temp;
TextToDisplay[i].SetString(temp);
Window.Draw(TextToDisplay[i]);
break;
}
}
Time is a timer i use to keep track of when the text should start scrolling and how far i am along. Then i cast it to an int to find how many characters i should show. TextLines is a stl vector holding strings for each line of text. Then text to display is a stl vector holding sf::Text for each line. I set the strings then display them, when I run out of characters I break. This is done each time step. Any help on a better implementation would be appreciated. Thanks.