From 22e5cba468a7d136aee1801c34623c3d0eb9f928 Mon Sep 17 00:00:00 2001 From: Gabe Hollombe Date: Sun, 17 Feb 2013 20:40:53 +1100 Subject: [PATCH] Only send player state when changed event is emitted by game.controls NOTE: requires update to player-physics module to emit this event --- client.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/client.js b/client.js index 29bc368..7ee566a 100644 --- a/client.js +++ b/client.js @@ -54,8 +54,7 @@ function connectToGameServer(socket) { function createGame(options) { options.controlsDisabled = false window.game = engine(options) - - setInterval(function() { + game.controls.on('changed', function() { if (!connected) return if (!game.controls.enabled) return var state = { @@ -66,7 +65,7 @@ function createGame(options) { } } emitter.emit('state', state) - }, 1000/22) + }); var container = document.querySelector('#container') game.appendTo(container)