P
P
Platov0802019-10-06 16:23:50
Game development
Platov080, 2019-10-06 16:23:50

Too slow character shift in the console, how to fix it?

When outputting to the console, the character movement animation is too slow. He seems to be dragging himself in the same position for several frames before he starts to change it.
I could not find anything on this problem, I do not even know how to formulate a query in a search engine. I thought the problem was in the video card, I did a clean reinstallation of the drivers, but it did not help.

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);
      }

    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question