При выведении в консоль анимация движения персонажа происходит слишком медленно. Он как буд-то тащится в одной и той же позе несколько кадров прежде чем начнет ее менять.
Ничего не смог найти по этой проблеме, даже не знаю как сформулировать запрос в поисковике. Думал проблема в видеокарте, сделал чистую переустановку драйверов, но не помогло.
float currentFrame = 0;
Sprite s;
s.setTexture(t);
s.setTextureRect(IntRect(0, 244, 40, 50));
s.setPosition(0, 50);
Clock clock;
while (window.isOpen())
{
float time = clock.getElapsedTime().asMicroseconds();
clock.restart();
time = time / 100;
Event event;
while (window.pollEvent(event))
{
if (event.type == Event::Closed)
{
window.close();
}
if (Keyboard::isKeyPressed(Keyboard::Left))
{
s.move(-0.1*time, 0);
currentFrame += 0.005*time;
if (currentFrame > 6) currentFrame -= 6;
s.setTextureRect(IntRect(40 * int(currentFrame)+40, 244, -40, 50));
}
if (Keyboard::isKeyPressed(Keyboard::Right))
{
s.move(0.1*time, 0);
currentFrame += 0.005*time;
if (currentFrame > 6) currentFrame -= 6;
s.setTextureRect(IntRect(40*int(currentFrame), 244, 40, 50));
}
if (Keyboard::isKeyPressed(Keyboard::Up))
{
s.move(0, -0.1);
}
}