place.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. function Place() {
  2. this.position = {x: 512, y: 512};
  3. this.width = 256;
  4. this.height = 256;
  5. this.spriteCanvas = null;
  6. this.spriteContext = null;
  7. this.lineWidth = 4;
  8. this.init = function() {
  9. this.preRender();
  10. }
  11. this.update = function(delta) {
  12. }
  13. this.preRender = function() {
  14. if(this.spriteContext == null) {
  15. this.spriteCanvas = document.createElement("canvas");
  16. this.spriteCanvas.width = this.width + (this.lineWidth * 2);
  17. this.spriteCanvas.height = this.height + (this.lineWidth * 2);
  18. this.spriteContext = this.spriteCanvas.getContext("2d");
  19. this.spriteContext.translate(0.5, 0.5);
  20. this.spriteContext.strokeStyle = "limegreen";
  21. this.spriteContext.lineWidth = this.lineWidth;
  22. this.spriteContext.beginPath();
  23. this.spriteContext.rect(1, 1, this.width, this.height);
  24. this.spriteContext.stroke();
  25. }
  26. }
  27. this.draw = function(context) {
  28. context.save();
  29. context.translate(this.position.x, this.position.y);
  30. context.drawImage(this.spriteCanvas, -parseInt(this.lineWidth / 4), -parseInt(this.lineWidth / 4));
  31. context.restore();
  32. }
  33. };