This is probably overkill and nooby but maybe you can reverse-engineer something out of this:
header:
class EEDelayedText : public sf::Text
{
private:
sf::Clock m_Clock;
sf::Time m_time,m_delay;
std::string m_string,m_buffer;
unsigned int current;
public:
EEDelayedText(const std::string& gstring,const sf::Font& gfont,unsigned int gsize);
~EEDelayedText(void);
void setString(const std::string& string);//covering text's setter
void setDelay(sf::Time gtime);
const EEDelayedText& update(void);
};
source:
#include "EEDelayedText.h"
EEDelayedText::EEDelayedText(const std::string& gstring,const sf::Font& gfont,unsigned int gsize):
sf::Text("",gfont,gsize),//can be changes probably, my sfml 2.0 is not latest so I miss some ctors
current(0),
m_string(gstring)
{
}
EEDelayedText::~EEDelayedText(void)
{
}
void EEDelayedText::setString(const std::string& gstring)
{
m_buffer.clear();
m_string=gstring;
current=0;
}
void EEDelayedText::setDelay(sf::Time gtime)
{
m_delay=gtime;
}
const EEDelayedText& EEDelayedText::update(void)
{
m_time+=m_Clock.restart();
while (m_time>=m_delay)
{
m_time-=m_delay;
if(current<m_string.length())
{
m_buffer+=m_string[current];
++current;
}
}
sf::Text::setString(m_buffer);//text's setString is covered, must call this way
return *this;
}
use:
sf::RenderWindow app(sf::VideoMode(600,600),"EEDelayedText");
sf::Font font;
font.loadFromFile("Resources/Main/arial.ttf");
EEDelayedText txt("Gott mit uns!",font,25);
txt.setDelay(sf::seconds(1.f/10.f));
while(1)
{
app.clear();
app.draw(txt.update());
app.display();
}
Add includes for sftext/whatever as needed, vc++ is a bit weird about that so there might be some missing.
This class is kind of ugly tbh, especially that lolzy .update() returning reference that window can use for drawing and that's about what you can do with it really because it's const reference.
Don't blame me if something explodes.