HeadsUpDisplay.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. class HeadsUpDisplay {
  2. constructor(game, camera) {
  3. this.player = null;
  4. this.hudCanvas = null;
  5. this.hudContext = null;
  6. }
  7. init(player, canvas) {
  8. this.player = player;
  9. this.hudCanvas = canvas;
  10. }
  11. update(delta) {
  12. }
  13. draw(context) {
  14. // context.strokeStyle = "white";
  15. // context.lineWidth = 10;
  16. // context.beginPath();
  17. // context.rect(5, 5, this.hudCanvas.width - 10, this.hudCanvas.height - 10);
  18. // context.stroke();
  19. context.save();
  20. context.translate(10, 10);
  21. var message = "2019 js13k Game";
  22. context.font = "16px sans-serif";
  23. context.textAlign = "left";
  24. context.textBaseline = "top";
  25. context.fillStyle = "#DDDDDD";
  26. context.strokeStyle = "#333333";
  27. context.lineWidth = 2;
  28. var textMetrics = context.measureText(message);
  29. var textWidth = textMetrics.width;
  30. context.fillText(message, 0, 0);
  31. context.restore();
  32. /*
  33. context.save();
  34. context.translate(this.player.position.x + camera.position.x, this.player.position.y + camera.position.y);
  35. context.font = "16px sans-serif";
  36. context.textAlign = "center";
  37. context.textBaseline = "middle";
  38. context.fillStyle = "#DDDDDD";
  39. context.strokeStyle = "#333333";
  40. context.lineWidth = 2;
  41. //var message = this.player.playerName + " " + this.player.id;
  42. //var textMetrics = context.measureText(message);
  43. //var textWidth = textMetrics.width;
  44. //context.fillText(message, 0, 0);
  45. var message = parseInt(this.player.position.x) + ", " + parseInt(this.player.position.y);
  46. var textMetrics = context.measureText(message);
  47. var textWidth = textMetrics.width;
  48. context.fillText(message, 0, 0);
  49. context.restore();
  50. */
  51. }
  52. }