ujs/src/js/app.js

28 lines
596 B
JavaScript
Raw Normal View History

2023-02-16 00:04:40 +03:00
import { Scene } from './scene.js';
import { Settings } from './settings.js';
import { Pointer } from './pointer.js';
2023-04-06 14:44:41 +03:00
export class App {
constructor(w, h) {
2023-04-06 15:03:09 +03:00
this.canvas = document.querySelector('canvas');
this.context = this.canvas.getContext('2d');
this.scene = new Scene(this.canvas, this.context, w, h);
2023-02-16 00:04:40 +03:00
this.prevTime = Date.now();
Pointer.init();
this.run();
}
run = () => {
let newTime = Date.now();
Settings.delta = (newTime - this.prevTime) / 1000;
this.prevTime = newTime;
this.scene.run();
requestAnimationFrame(this.run);
2023-04-06 18:03:40 +03:00
};
2023-02-16 00:04:40 +03:00
}