npm install. This will install the server-side JavaScript dependencies into node_modules/../bin/wwwpublic called assets.public/assets:
public/javascript/game.js with this example file:
game.js, find the line that executes new Phaser.Game and replace its 4th argument from phaser-example to phaser
<div> ID specified in the template.preload() to match the path we downloaded everything to—namely, assets/ (the web framework removes the public part).layer.debug to be true to see collision../bin/wwwpublic/javascripts/game.js: https://gist.github.com/awwong1/20b3acea02019f43a88fAdd the client WebSocket instantiation at the bottom of the create() method:
this.client = new Client();
this.client.openConnection();app.js) to handle players instead of the one rabbit object: https://gist.github.com/awwong1/90d50ffa41cfc5ef7ea4Set the variables of the class within game.js to equal the following:
var map;
var layer;
var cursors;
var players = {};
var id = guid();
players[id] = {};
var player = players[id];Add the following code to the bottom of the update() method:
if (this.client.connected) {
this.client.ws.send(JSON.stringify({
uuid: id,
x: player.x,
y: player.y
}));
}onMessage() function to equal the following: https://gist.github.com/awwong1/2280e439b81c0fa666f7Run the application. Open up a new browser window and run the application. What happens?
Client class do?WebSockets require callback methods. In the openConnection() method of the Client, these are set by using the following:
this.ws.onmessage = this.onMessage.bind(this).
this.ws.onerror = this.displayError.bind(this);
this.ws.onopen = this.connectionOpen.bind(this);Why is Function#bind() necessary? In other words, why couldn’t the code just do this?
this.ws.onmessage = this.onMessage;
this.ws.onerror = this.displayError;
this.ws.onopen = this.connectionOpen;What is Phaser (in the context of this lab)?