Skip to content

Instantly share code, notes, and snippets.

@z3t0
Last active July 29, 2016 00:08
Show Gist options
  • Select an option

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

Select an option

Save z3t0/5e626d60e225cadf767d90d0689d44dd 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(this);
console.log("Trying to connect...");
self.ws = new WebSocket(this.host);
self.ws.onopen = self.OnConnectHandler;;
self.ws.onmessage = self.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