I'm currently trying to program my first game in SFML (and my first general one), but I ran into a problem that I stutter about once per second. During such a stutter, Frametime is 3-4 times higher than usual, which is really noticeable, since I am not launching a really high FPS (300+).
There is no problem (atm at least), since performance is not a problem, but:
When I do this, my Method method is really worried and moves slower than it should.
my move method:
void Player::Update(float frametime){ mMovementSpeedTimefactor = frametime * 60 / 1000.0f; setMovementVector(sf::Vector2f( mMovementVector.x * mMovementSpeedTimefactor, mMovementVector.y *mMovementSpeedTimefactor)); validateMovement(); //std::cout << mTestClock->restart().asMilliseconds() << std::endl; moveObject(); this->updateAnimation(); }
frametime is the cycle time in milliseconds, and I am multiplying by 60, since the speed of movement is defined as a value for a pixel / second, and not for a frame.
movementpeed is 5, so the character must move 5 pixels per second, regardless of FPS (and therefore Frametime).
But: this gives me a really jumping movement, since those โstutterframesโ lead to a jump, and on nto stuttering frames the palyer moves much slower than necessary.
my mainloop is really simple, just
while(mMainWindow->isOpen()){ HandleEvents(); Update(); Render(); }
when using the built-in framework (I tried to write my own, but I get the same result if I use sf: sleep to regulate FPS for the lack of a processor core with 100% load) to 300 FPS.
So yes, I could just set the default speed to 1 instead of 5, but setframeratelimit is not very accurate, so I get some changes in motionpeed that I really don't like.
Does anyone have an idea what I could best do? Maybe I donโt see the forest for all the trees (I really have no idea if you say this in English: P), but since this is my first game, I have no experience looking back.