Static frame rate established
This commit is contained in:
parent
e75db5affd
commit
46c584d9ee
20
js/module.js
20
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);
|
||||
}
|
||||
);
|
||||
);
|
||||
|
@ -276,4 +276,4 @@ export default class RetroArchitecture
|
||||
|
||||
return architecture;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user