Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Auto typing character by character  (Read 2473 times)

0 Members and 1 Guest are viewing this topic.

marianexyx

  • Newbie
  • *
  • Posts: 11
    • View Profile
Auto typing character by character
« on: March 18, 2015, 01:38:32 am »
Hello. I'm trying to make Fallout 3 terminal application (). 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 :)

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Auto typing character by character
« Reply #1 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.
« Last Edit: March 18, 2015, 01:49:56 am by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

marianexyx

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Auto typing character by character
« Reply #2 on: March 18, 2015, 10:23:50 pm »
It works great! Thanks a lot