Optimization for Firefox and Chrome

This commit is contained in:
Mal
2021-09-21 09:47:27 +02:00
parent 46c584d9ee
commit 598dbc67ac
3 changed files with 63 additions and 11 deletions

View File

@@ -112,7 +112,16 @@ function MainLoop(timestamp)
}
context.clearRect(0, 0, window.innerWidth, window.innerHeight);
architecture.draw(context, camera);
switch (browser) {
case 'Chrome':
architecture.drawForChrome(context, camera);
break;
default:
architecture.drawForFirefox(context, camera);
}
mrCroc.draw(context, camera);
gisela.draw(context, camera);
userInterface.draw(context);
@@ -154,7 +163,8 @@ let level = Level.createFromFile(Setting.LEVELS_LOCATION + LEVEL[levelIndex]);
const GAME_SPEED = 1;
const GRAVITY = level.gravity;
let fps = 120;
let fps = 60;
const browser = navigator.userAgent.indexOf('Firefox') === -1 ? 'Chrome' : 'Firefox';
let frameDuration;
let lastRendered = undefined;
let lastTimestamp = undefined;
@@ -179,8 +189,6 @@ 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();
window.addEventListener(
'imagesloaded',
() => {