SFML community forums

Help => General => Topic started by: marianexyx on March 18, 2015, 01:38:32 am

Title: Auto typing character by character
Post by: marianexyx on March 18, 2015, 01:38:32 am
Hello. I'm trying to make Fallout 3 terminal application (https://www.youtube.com/watch?v=RxSvk40Ka9U&t=161). I can't figure out how to make text shown character by character. Found some code that works in regular C++ console app:

std::string str = "some text";
for (unsigned i = 0; i < str.length(); i++)
        {
                cout << str[i];

                if ((i + 1) < str.length() && str[i + 1] != '\n')
                        cout << char(219);

                _sleep(6);

                if ((i + 1) < str.length() && str[i + 1] != '\n')
                        cout << char(8);
        }
        cout << ' ' << char(8);

And there goes my questions:
1. How can I use in SFML's Text class something like:

sf::Text str = "some text";
window.draw(str[i]);
?

2. How can I parse char to sf::Text, and then draw it, like in cout's example above?

3. Didn't test, but is the _sleep(n) command is proper for SFML program loop?

PS. Please note I'm novice in C++ and with English language :)
Title: Re: Auto typing character by character
Post by: zsbzsb on March 18, 2015, 01:44:57 am
If you want to show text letter by letter I wrote a small example some time ago to do that. Copy and paste the following gist and then type some text into the window to see if that is what you want. Text will be shown letter by letter with a 1/2 second interval.

https://gist.github.com/zsbzsb/7e700828ce2639cdaa99

And if that is what you want I am sure you can extend it and apply the principles to your situation.
Title: Re: Auto typing character by character
Post by: marianexyx on March 18, 2015, 10:23:50 pm
It works great! Thanks a lot