headsupdisplay.js 1.4 KB

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