Skip to content

Instantly share code, notes, and snippets.

@z3t0
Created July 29, 2016 00:05
Show Gist options
  • Select an option

  • Save z3t0/5c1ec891ae5b4536c09389228291816c to your computer and use it in GitHub Desktop.

Select an option

Save z3t0/5c1ec891ae5b4536c09389228291816c to your computer and use it in GitHub Desktop.
var pixi = require('pixi.js');
module.exports = function(host) {
return new game(host);
}
function game (host) {
this.host = host;
console.log("creating game")
if (host == "") {
console.log("no host provided");
return;
}
this.players = []
this.connect();
// this.init();
}
game.prototype.init = function() {
self = this;
console.log("initializing pixi")
// setup pixi.js
self.renderer = pixi.autodetectrenderer(256, 256);
document.body.appendchild(renderer.view);
self.stage = new pixi.container();
self.renderer.view.style.position = "absolute";
self.renderer.view.style.display = "block";
self.renderer.autorescale = true;
self.renderer.resize(window.innerwidth, window.innerheight);
self.renderer.render(self.stage);
}
game.prototype.connect = function() {
console.log("trying to connect...");
self.ws = new websocket(this.host);
self.ws.onopen = self..onconnecthandler;;
self.ws.onmessage = self.j.messagehandler;
self.ws.onclose = self.closehandler;
}
game.prototype.onconnecthandler = function() {
self = this;
console.log("connection with '" + self.host + "' established");
// this.ws.send('a');
console.log(this.ws);
console.log(self.ws)
}
game.prototype.messagehandler = function(msg) {
self = this;
console.log("got message: " + msg.data);
}
game.prototype.closehandler = function(e) {
self = this;
console.log("closed: " + e.data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment