Static frame rate established

This commit is contained in:
Mal 2021-09-15 17:24:53 +02:00
parent e75db5affd
commit 46c584d9ee
2 changed files with 8 additions and 14 deletions

View File

@ -103,6 +103,8 @@ function MainLoop(timestamp)
/* Drawing */
if (timestamp - lastRendered >= frameDuration) {
lastRendered = timestamp;
if (gisela.currentAnimation !== 'LOOK_LEFT' && mrCroc.position.x < gisela.position.x) {
gisela.currentAnimation = 'LOOK_LEFT';
} else if (gisela.currentAnimation !== 'LOOK_RIGHT' && mrCroc.position.x >= gisela.position.x) {
@ -114,8 +116,6 @@ function MainLoop(timestamp)
mrCroc.draw(context, camera);
gisela.draw(context, camera);
userInterface.draw(context);
lastRendered = timestamp;
}
lastTimestamp = timestamp;
@ -154,7 +154,7 @@ let level = Level.createFromFile(Setting.LEVELS_LOCATION + LEVEL[levelIndex]);
const GAME_SPEED = 1;
const GRAVITY = level.gravity;
let fps;
let fps = 120;
let frameDuration;
let lastRendered = undefined;
let lastTimestamp = undefined;
@ -179,7 +179,7 @@ loader.addImage(Setting.TILESET_LOCATION + GraphicSet[level.getTilesetId()].tile
loader.addImage(Setting.GRAPHICS_LOCATION + 'gisela-right.png');
loader.addImage(Setting.GRAPHICS_LOCATION + 'gisela-left.png');
new FrameRateMeasurer();
// new FrameRateMeasurer();
window.addEventListener(
'imagesloaded',
@ -227,13 +227,7 @@ window.addEventListener(
gisela = new Gisela();
architecture.setMovableToTargetPosition(gisela);
window.addEventListener(
InterfaceEvent.FRAME_RATE_MEASURED,
(event) => {
fps = event.frameRate;
frameDuration = 1000 / fps;
window.requestAnimationFrame(MainLoop);
}
);
frameDuration = 1000 / fps;
window.requestAnimationFrame(MainLoop);
}
);
);

View File

@ -276,4 +276,4 @@ export default class RetroArchitecture
return architecture;
}
}
}