}
Game.prototype.start = function(ms) {
- var me = this;
- var tmpfn = function() {me.getNextFrame()};
+ var _this = this;
+ var tmpfn = function() {_this.getNextFrame()};
this.timeout = setInterval(tmpfn, ms);
}
Game.prototype.getNextFrame = function() {
- console.log(this);
var inputs = this.players.map(function(p) {return p.get_status();});
this.state.update(inputs);
var state = this.state.getState();
function Player(ws) {
this.status = 'x';
this.socket = ws;
- this.socket.onmessage = this.listener;
+ var _this = this;
+ var fn = function(msg) {
+ _this.listener(msg);
+ }
+ this.socket.onmessage = fn;
}
+// this should probably be renamed...
Player.prototype.listener = function(msg) {
var data = msg.data;
if(typeof data == "string" && data.length > 0) {