1234567891011121314151617181920212223242526272829 |
- import { ScaledCanvas } from './ScaledCanvas.js';
- export class CanvasRenderer {
- constructor() {
- this.context = null;
- this.scaledCanvas = null;
- }
- init(container, scene) {
- this.scaledCanvas = new ScaledCanvas(container);
- this.scaledCanvas.init();
- this.context = this.scaledCanvas.getContext();
- this.setScene(scene);
- }
- animate() {
- this.scaledCanvas.clearFrame();
- this.scene.draw(this.scaledCanvas.getContext());
- requestAnimationFrame(this.animate.bind(this));
- }
- setScene(scene) {
- this.scene = scene;
- }
- start() {
- this.animate();
- }
- }
|