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

View File

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