From 46c584d9eef9a49a7a7ebffbc1be6745d14b1f5a Mon Sep 17 00:00:00 2001 From: Mal Date: Wed, 15 Sep 2021 17:24:53 +0200 Subject: [PATCH] Static frame rate established --- js/module.js | 20 +++++++------------- js/retro/RetroArchitecture.js | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/js/module.js b/js/module.js index c1942e8..543759d 100644 --- a/js/module.js +++ b/js/module.js @@ -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); } -); \ No newline at end of file +); diff --git a/js/retro/RetroArchitecture.js b/js/retro/RetroArchitecture.js index bdd2be9..4a4bf5b 100644 --- a/js/retro/RetroArchitecture.js +++ b/js/retro/RetroArchitecture.js @@ -276,4 +276,4 @@ export default class RetroArchitecture return architecture; } -} \ No newline at end of file +}