mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
added stats + ping, fixed box2d step size
This commit is contained in:
parent
ffb7db528a
commit
b4ef1203b1
8 changed files with 63 additions and 16 deletions
|
|
@ -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;
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue