CanvasRenderer.js 697 B

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