I've tried to implement frame-independent movement for my player, and it should be working, but I'm still seeing slowdown in player movement.
Not sure if this is relevant to the question, but for my player I'm using tile movement (Basically when you press a direction key the player will move a fixed distance over a few frames until it reaches the next tile. When I press a direction key, the player's clock is restarted and a bool
isMoving is set to true until the player reaches the next tile. With that said, here's just a minimal example of where I've used the clock for frame-independent movement:
if (isMoving)
{
if (clock.getElapsedTime().asSeconds() > (1 / 30))
{
move(/* For now this is 2 pixels in the desired direction */);
movePixelsLeft -= speed; // when this reaches 0 it means the player has reached the next tile
clock.restart();
}
if (movePixelsLeft <= 0)
{
isMoving = false;
if (getColMapPosNum() > 1)
{
isMoving = false;
// some other stuff
}
}
}
On a side note, my game seems to be unable to go over 40FPS, is there anything i can do to improve performance?