added stats + ping, fixed box2d step size

This commit is contained in:
Jeena 2013-12-09 14:00:46 +01:00
parent ffb7db528a
commit b4ef1203b1
8 changed files with 63 additions and 16 deletions

View file

@ -63,8 +63,22 @@ function (ProtocolHelper, GameController, User, NotificationCenter) {
console.log("already spawned player, options: ", options.spawnedPlayers[i])
}
}
this.initPing();
}
Networker.prototype.initPing = function() {
this.pingDOMElement = document.createElement("span");
this.pingDOMElement.style.color = "white";
this.pingDOMElement.style.fontFamily = "monospace";
document.body.appendChild(this.pingDOMElement);
this.ping();
};
Networker.prototype.ping = function() {
this.sendCommand("ping", Date.now());
};
// Sending commands
@ -97,6 +111,11 @@ function (ProtocolHelper, GameController, User, NotificationCenter) {
ProtocolHelper.applyCommand(message, this.gameController);
}
Networker.prototype.onPong = function(timestamp) {
this.pingDOMElement.innerHTML = "Ping: " + (Date.now() - parseInt(timestamp, 10));
setTimeout(this.ping.bind(this), 1000);
};
return Networker;
});