Static frame rate established
This commit is contained in:
parent
e75db5affd
commit
46c584d9ee
14
js/module.js
14
js/module.js
|
@ -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(
|
|
||||||
InterfaceEvent.FRAME_RATE_MEASURED,
|
|
||||||
(event) => {
|
|
||||||
fps = event.frameRate;
|
|
||||||
frameDuration = 1000 / fps;
|
frameDuration = 1000 / fps;
|
||||||
window.requestAnimationFrame(MainLoop);
|
window.requestAnimationFrame(MainLoop);
|
||||||
}
|
}
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
);
|
Loading…
Reference in New Issue