update app class

This commit is contained in:
Alexander Popov 2023-12-01 16:35:43 +03:00
parent cc8a51749a
commit bdec83fd32
Signed by: iiiypuk
GPG Key ID: E47FE0AB36CD5ED6

View File

@ -7,8 +7,8 @@ export class App {
#version; #version;
constructor( constructor(
w, width,
h, height,
options = { options = {
backgroundColor: '#ffcc68', backgroundColor: '#ffcc68',
welcome: true, welcome: true,
@ -16,12 +16,12 @@ export class App {
) { ) {
this.#version = 'beeeeeeta'; this.#version = 'beeeeeeta';
// Create CANVAS element
this.view = document.createElement('canvas'); this.view = document.createElement('canvas');
this.canvas = this.view; this.canvas = this.view;
this.context = this.canvas.getContext('2d'); this.context = this.canvas.getContext('2d');
this.options = options;
this.options = options;
// check options || FIXIT: // check options || FIXIT:
if (typeof this.options.backgroundColor === 'undefined') { if (typeof this.options.backgroundColor === 'undefined') {
this.options.backgroundColor = '#ffcc68'; this.options.backgroundColor = '#ffcc68';
@ -30,8 +30,7 @@ export class App {
this.options.welcome = true; this.options.welcome = true;
} }
this.scene = new Scene(this.canvas, this.context, w, h); this.scene = new Scene(this.canvas, this.context, width, height);
Settings.fpsPrevTime = Date.now();
const logStrings = [ const logStrings = [
'ujs engine', 'ujs engine',
@ -47,7 +46,9 @@ export class App {
} }
Pointer.init(); Pointer.init();
Settings.fpsPrevTime = Date.now();
// Start :)
this.run(); this.run();
} }
@ -58,18 +59,14 @@ export class App {
Settings.fpsPrevTime = fpsNewTime; Settings.fpsPrevTime = fpsNewTime;
Settings.fps = Math.round(1 / Settings.fpsDelta); Settings.fps = Math.round(1 / Settings.fpsDelta);
// clear canvas // Clear canvas
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height); this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
// fill canvas // Fill canvas by default background color
this.context.fillStyle = this.options.backgroundColor; this.context.fillStyle = this.options.backgroundColor;
this.context.fillRect(0, 0, this.canvas.width, this.canvas.height); this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
// draw border // Draw scene
this.context.strokeStyle = '#101024';
this.context.lineWidth = 1;
this.context.strokeRect(5, 5, this.canvas.width - 10, this.canvas.height - 10);
this.scene.run(); this.scene.run();
requestAnimationFrame(this.run); requestAnimationFrame(this.run);