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 - gonzalo_

Pages: [1]
1
Graphics / Re: TextEntered input repeats
« on: July 07, 2022, 02:37:30 am »
Great, that was the trouble. Thank you very much!!!

2
Graphics / TextEntered input repeats
« on: July 06, 2022, 01:39:07 am »
Hello there! I am completely new to SFML and C++ and right now I am working on a university project in which I have to program a game...

I need the name of the player, so I use  sf::Event::TextEntered event to catch text input, and a sf::String to display it. Also, I follow some examples that I saw in this thread https://en.sfml-dev.org/forums/index.php?topic=1451.0 that were really useful.

But the issue is that, although I can catch the input and show it, it catches more than one input for the same letter. For example, I press 'A', and it shows me 'AAA' o perhaps 'AAAA'. 

Any help is welcome

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

    if (event.type == sf::Event::TextEntered)
    {
        player.insertName(static_cast<char>(event.text.unicode));
        player.update();
    }
...


Quote
void Player::update()
{
        _playerText.setString(_playerInput);
}

Quote
       
void Jugadorxs::innsertName(int unicode)
{
if (unicode == 8) { //If backspace
                if (textSize > 0)
                        _playerInput.erase(static_cast<size_t>(textSize) - 1, 1);
        }
        else if (unicode >= 32 && unicode <= 126) {
                _playerInput += (char)unicode;
        }
        else if (unicode >= 192 && unicode <= 255) {
                _playerInput += (char)unicode;
        }    
}

Pages: [1]