I'm testing displaying text in sfml 2.0, "typewriter" style. The way it's working now, it works properly for the first seven characters, then it all goes to hell. Even weirder, the text gets smaller every time I access the message. I don't know what I'm doing wrong here!
Here's some relevant code--if more is needed, let me know.
Message structure:
void Message::Create(string file, string key, float xx, float yy, float ww, float hh, float sz) {
string temp;
ifstream istream(file);
//until the stream finds the search term to search in the text document, it will iterate through it.
for(file; temp.find(key) == -1; getline(istream, temp));
for(file; temp != "[end]"; text += temp, getline(istream, temp));
x = y = 0;
w = ww; h = hh; size = sz;
pos = 0;;
pause = done;
print = undone;
//Display is a Canvas structure which contains an sf::RenderTexture (buff) among other values
Display.Make(w, h);
Display.Set(xx, yy);
Display.buff.Clear(BLACK);
//Data is sf::Text
Data.SetString(text.at(pos));
Data.SetPosition(0, 0);
Data.SetCharacterSize(size);
istream.close();
}
void Message::Logic() {
if (print) return;
++pos;
if (pos == text.length() - 1) {
print = done;
return;
}
x + Data.GetRect().Width > w? x = 0, y += Data.GetRect().Height: x += Data.GetRect().Width;
Data.SetString(text.at(pos));
Data.SetPosition(x, y);
}
void Message::Drawing() {
Display.DrawText(Data);
Display.Refresh();
Display.Blit(*Buffer);
}
Relevant Canvas structure :
void Canvas::Make(short ww, short hh) {
w = ww; h = hh; x = y = 0;
buff.Create(ww, hh); //buff = sf::RenderTexture
buff.Clear(CLEAR);
img = this->buff.GetTexture(); //img = sf::Texture
spr.SetTexture(img); //sf::Sprite
}
void Canvas::Set(float xx, float yy) {
x = xx; y = yy;
spr.SetPosition(x, y);
}
void Canvas::DrawText(sf::Text txt) {
buff.Draw(txt);
this->Refresh();
}
void Canvas::Blit(Canvas &bb) {
img = buff.GetTexture();
bb.Draw(*this);
}
void Canvas::Refresh() {
buff.Display();
}
//pasted from header file for relevance:
template<class Object>
void Draw(Object &gfx) {
buff.Draw(gfx.spr);
this->Refresh();
}