Camera.js 581 B

123456789101112131415161718192021222324
  1. import { Point } from "./spatial/Point.js";
  2. export class Camera {
  3. constructor(x = 0, y = 0) {
  4. this.position = new Point(x,y)
  5. }
  6. update(delta) {
  7. }
  8. drawAtCameraCentered(ctx, drawFunc) {
  9. ctx.save();
  10. ctx.translate(-this.position.x + (Global.screenBounds.width / 2), -this.position.y + (Global.screenBounds.height / 2));
  11. drawFunc(ctx);
  12. ctx.restore();
  13. }
  14. drawAtCamera(ctx, drawFunc) {
  15. ctx.save();
  16. ctx.translate(-this.position.x, -this.position.y);
  17. drawFunc(ctx);
  18. ctx.restore();
  19. }
  20. }