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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Paradoxic4

Pages: [1]
1
Graphics / Re: using the erase function of sf::sting
« on: May 24, 2014, 11:53:47 pm »
Thank you Geheim, that worked perfectly!  Do you have any idea as to why that works, but my original code did not?

2
Graphics / using the erase function of sf::sting
« on: May 21, 2014, 06:56:13 am »
The following code produces some odd behavior.  As the attached pictures show, I am able to input text just fine, but when I press backspace, it changes the last character to that little circle, after which pressing backspace again does nothing.  This seems to imply to me that the place in the sf::string which once held the last character still exists, and that pressing backspace repeatedly just continually replaces the last character with the little circle.  Hence, the string has not changes size, and calling getSize() will continue to produce the same number at every frame.  Is this supposed to be the case, or am I doing something wrong?  Thank you for your help.

int main()
{
        sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
        sf::Font myFont;
        if (!myFont.loadFromFile("resources/roman.ttf"))
        {
                cout << "The font was not loaded!\n";
        }

        sf::Text Text;
        Text.setFont(myFont);
        Text.setCharacterSize(24);
        Text.setColor(sf::Color::Red);
        Text.setPosition(10, 10);

        sf::String userInput;


        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                        {
                                window.close();
                        }

                        if (event.type == sf::Event::TextEntered)
                        {
                                userInput.insert(userInput.getSize(), event.text.unicode);
                        }
                       
                        if (event.type == sf::Event::KeyPressed)
                        {
                                if (event.key.code == sf::Keyboard::BackSpace)
                                {
                                        userInput.erase(userInput.getSize() - 1,1);
                                }
                        }
                }
               
                Text.setString(userInput.getData());

                window.clear();
                window.draw(Text);
                window.display();
        }

        return 0;
}
 

Pages: [1]