Skip to content
Snippets Groups Projects
Commit 42b98d43 authored by Tran Peter's avatar Tran Peter
Browse files

fix(game scene): fix animation timer too fast for high fps

parent ff6e4ed5
No related branches found
No related tags found
5 merge requests!74V1,!73Initial commit,!71Merge DataBase into Development,!54Update: coreMaps.json (added new maps),!49Merge ui into development
......@@ -85,6 +85,8 @@ public class GameSceneController implements Initializable {
int diffTileCount = 30;
int scaledTileSize = 48;
private final Biom biom = runtimeInfo.getMapBiom();
private final long targetFrameTime = 1_000_000_000 / 80; // sets the target frame time to 12.5 ms (80fps)
private long lastFrame = 0;
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
......@@ -142,11 +144,15 @@ public class GameSceneController implements Initializable {
AnimationTimer gameLoop = new AnimationTimer() {
@Override
public void handle(long l) {
public void handle(long now) {
if (!inputHandler.isPause()) {
graphicsContext2D.clearRect(0, 0, canvas2D.getWidth(), canvas2D.getHeight());
renderContent(graphicsContext2D);
updateContent();
if (now - lastFrame >= targetFrameTime) { // If short frame time (high fps) it will skip updateContent(). Next Frame has higher frame time and updates the frame
graphicsContext2D.clearRect(0, 0, canvas2D.getWidth(), canvas2D.getHeight());
renderContent(graphicsContext2D);
updateContent();
lastFrame = now;
}
// remove blur
if (wasPaused) {
resume();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment