improve syncing

This commit is contained in:
biglyderv 2024-11-25 14:14:20 -05:00
parent 0ea8236567
commit 9353f7cbf0
2 changed files with 3 additions and 2 deletions

View file

@ -26,7 +26,7 @@ class Game extends GameBasic {
let that = this; let that = this;
that.entities = []; that.entities = [];
setInterval(function () { that.sync() }, 1000 / 20); setInterval(function () { that.sync() }, 1000 / 5);
} }
} }

View file

@ -82,6 +82,7 @@ class Game extends GameBasic {
this.entities.push(this.player); this.entities.push(this.player);
} else { } else {
player.bump(); player.bump();
this.ws.send(JSON.stringify({ vel, dir, you }));
} }
} }
sync() { sync() {
@ -119,7 +120,7 @@ class Game extends GameBasic {
this.ws.addEventListener('message',function(e) { that.recv(e) }); this.ws.addEventListener('message',function(e) { that.recv(e) });
setInterval(function () { that.render() }, 1000 / 60); setInterval(function () { that.render() }, 1000 / 60);
setInterval(function () { that.sync() }, 1000 / 20); setInterval(function () { that.sync() }, 1000 / 5);
game.canvas.onclick = () => that.click(); game.canvas.onclick = () => that.click();
} }