Bonjour,
je souhaite déplacer un petit carré, j'y arrive bien sauf que lorsque je change de touche en plein déplacement, je constate une petit délai avant que mon carré se déplace à nouveau.
Voici le code :
// Boucle
while (window.isOpen())
{
sf::Time elapsedTime = clock.restart();
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
window.close();
}
if(!isKeyPressed || keyPressed == LEFT)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
rect.move(-RECT_SPEED*elapsedTime.asMilliseconds(), 0);
isKeyPressed = true;
keyPressed = LEFT;
}
}
if(!isKeyPressed || keyPressed == RIGHT)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
rect.move(RECT_SPEED*elapsedTime.asMilliseconds(), 0);
isKeyPressed = true;
keyPressed = RIGHT;
}
}
if(!isKeyPressed || keyPressed == UP)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
rect.move(0, -RECT_SPEED*elapsedTime.asMilliseconds());
isKeyPressed = true;
keyPressed = UP;
}
}
if(!isKeyPressed || keyPressed == DOWN)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
rect.move(0, RECT_SPEED*elapsedTime.asMilliseconds());
isKeyPressed = true;
keyPressed = DOWN;
}
}
if(event.type == sf::Event::KeyReleased)
isKeyPressed = false;
}
window.clear(sf::Color(0,162,255));
window.draw(rect);
window.display();
}