From 13e8784652d01ef2ffb51b7a777a2b77455794e2 Mon Sep 17 00:00:00 2001 From: onezDerv Date: Sun, 29 Sep 2024 17:07:22 -0400 Subject: [PATCH] improve syncing --- game.js | 2 +- static/js/index.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/game.js b/game.js index a3d422c..9e79a8d 100644 --- a/game.js +++ b/game.js @@ -26,7 +26,7 @@ class Game extends GameBasic { let that = this; that.entities = []; - setInterval(function () { that.sync() }, 1000 / 20); + setInterval(function () { that.sync() }, 1000 / 5); } } diff --git a/static/js/index.js b/static/js/index.js index 13d483e..f9d5aa2 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -82,6 +82,7 @@ class Game extends GameBasic { this.entities.push(this.player); } else { player.bump(); + this.ws.send(JSON.stringify({ vel, dir, you })); } } sync() { @@ -119,7 +120,7 @@ class Game extends GameBasic { this.ws.addEventListener('message',function(e) { that.recv(e) }); setInterval(function () { that.render() }, 1000 / 60); - setInterval(function () { that.sync() }, 1000 / 20); + setInterval(function () { that.sync() }, 1000 / 5); game.canvas.onclick = () => that.click(); }