46
General / Re: I'm losing my mind implementing a fixed frame rate.
« on: February 04, 2024, 12:55:26 pm »
It's important to realise that "position" is never aware of what the graphics are doing. It's the thing that is updated and should not affected by any of the "graphics effects", which is what interpolation is.
This means that "position" should not be set to the circle's position as the circle has been adjusted by interpolation. The position value should continue as if interpolation never happened. The interpolation is only added as an "visual effect" to adjust what we see; it shouldn't be a part of the logic (the actual position).
To fix this, remove "position = circle.getPosition();". The circle should not be affecting what position does.
Shouldn't the "within main loop" section be within the loop?
After that, you could consider adding vertical sync to reduce the number of actual frames. The good thing about this setup is that the logic will not change at all; it will still make the same identical calculations in the updates because the amount of time processed is always the same, regardless of how long it took since the last frame. The only calculations that change are visual (the interpolation) and these should not be affecting the actual logic. If vertical sync isn't an option, you could always use setFramerateLimit.
This means that "position" should not be set to the circle's position as the circle has been adjusted by interpolation. The position value should continue as if interpolation never happened. The interpolation is only added as an "visual effect" to adjust what we see; it shouldn't be a part of the logic (the actual position).
To fix this, remove "position = circle.getPosition();". The circle should not be affecting what position does.
Shouldn't the "within main loop" section be within the loop?
After that, you could consider adding vertical sync to reduce the number of actual frames. The good thing about this setup is that the logic will not change at all; it will still make the same identical calculations in the updates because the amount of time processed is always the same, regardless of how long it took since the last frame. The only calculations that change are visual (the interpolation) and these should not be affecting the actual logic. If vertical sync isn't an option, you could always use setFramerateLimit.