}); | }); | ||||
sock.on("set", (msg) => { | sock.on("set", (msg) => { | ||||
console.log(msg); | |||||
if (!this.entities[msg.id]) | if (!this.entities[msg.id]) | ||||
this.entities[msg.id] = createEntity(msg); | this.entities[msg.id] = createEntity(msg); | ||||
else | else | ||||
this.raf = window.requestAnimationFrame(this.update.bind(this)); | this.raf = window.requestAnimationFrame(this.update.bind(this)); | ||||
} | } | ||||
stop() { | |||||
window.cancelAnimationFrame(this.raf); | |||||
} | |||||
} | } |
document.querySelector("#startGameBtn").addEventListener("click", () => { | document.querySelector("#startGameBtn").addEventListener("click", () => { | ||||
view("game"); | view("game"); | ||||
let sock = new SockSugar("ws://localhost:8081"); | |||||
let sock = new SockSugar("ws://serve.mort.coffee:89"); | |||||
let game = new Game(sock, document.getElementById("canvas")); | let game = new Game(sock, document.getElementById("canvas")); | ||||
sock.on("close", () => { | |||||
alert("Server closed."); | |||||
game.stop(); | |||||
}); | |||||
}); | }); |