Created
July 29, 2016 00:05
-
-
Save z3t0/5c1ec891ae5b4536c09389228291816c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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