CanvasRenderer.js 661 B

1234567891011121314151617181920212223242526272829
  1. import { ScaledCanvas } from './ScaledCanvas.js';
  2. export class CanvasRenderer {
  3. constructor() {
  4. this.context = null;
  5. this.scaledCanvas = null;
  6. }
  7. init(container, scene) {
  8. this.scaledCanvas = new ScaledCanvas(container);
  9. this.scaledCanvas.init();
  10. this.context = this.scaledCanvas.getContext();
  11. this.setScene(scene);
  12. }
  13. animate() {
  14. this.scaledCanvas.clearFrame();
  15. this.scene.draw(this.scaledCanvas.getContext());
  16. requestAnimationFrame(this.animate.bind(this));
  17. }
  18. setScene(scene) {
  19. this.scene = scene;
  20. }
  21. start() {
  22. this.animate();
  23. }
  24. }