There were problems in the management of the sprite. I store the control key codes in (int keyLeft, keyRight), they can be changed. Windows system delay appears before continuous key input. If I close the while loop after the window.close () line, the sprite is constantly moving left or right after a single key press.

while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); if (sf::Event::KeyPressed) { if(event.key.code==keyLeft) ball.x-=15+platSpeed/2,0; else if(event.key.code==keyRight) ball.x+=15+platSpeed/2,0; else if(event.key.code==27) menu(window, text); } } 

    1 answer 1

    Try using sf :: Keyboard :: isKeyPressed () instead of Event. Also, the cycle of checking the "Closed" event is best done separately from processing. For example, like this:

     struct Keys { sf::Keyboard::Key keyLeft = sf::Keyboard::A; sf::Keyboard::Key keyRight = sf::Keyboard::D; sf::Keyboard::Key keyMenu = sf::Keyboard::F; } keys; while (window.isOpen()) { while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); } if(sf::Keyboard::isKeyPressed(keys.keyLeft)) ball.x-=15+platSpeed/2,0; if(sf::Keyboard::isKeyPressed(keys.keyLeft)) ball.x+=15+platSpeed/2,0; if(sf::Keyboard::isKeyPressed(keys.keyMenu)) menu(window, text); }