瀏覽代碼

done things

master
mort 8 年之前
父節點
當前提交
aa89dcd4cb
共有 2 個檔案被更改,包括 10 行新增2 行删除
  1. 4
    1
      es/game.js
  2. 6
    1
      es/script.js

+ 4
- 1
es/game.js 查看文件

}); });


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);
}
} }

+ 6
- 1
es/script.js 查看文件



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();
});
}); });

Loading…
取消
儲存