From 0ca82b9564b0461f661455efa464e35b6ab4ee3b Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Fri, 1 Dec 2023 15:55:39 +0300 Subject: [PATCH] fps delta move to Settings --- src/main.js | 9 +++++---- src/objects.js | 12 ++++++------ src/scene.js | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main.js b/src/main.js index 200a3d7..bbc9d0f 100644 --- a/src/main.js +++ b/src/main.js @@ -12,7 +12,7 @@ export class App { options = { backgroundColor: '#ffcc68', welcome: true, - }, + } ) { this.#version = 'beeeeeeta'; @@ -31,7 +31,7 @@ export class App { } this.scene = new Scene(this.canvas, this.context, w, h); - this.prevTime = Date.now(); + Settings.prevTime = Date.now(); const logStrings = [ 'ujs engine', @@ -51,9 +51,10 @@ export class App { } run = () => { + // Calculating FPS let newTime = Date.now(); - Settings.delta = (newTime - this.prevTime) / 1000; - this.prevTime = newTime; + Settings.delta = (newTime - Settings.prevTime) / 1000; + Settings.prevTime = newTime; // clear canvas this.context.clearRect(0, 0, this.canvas.width, this.canvas.height); diff --git a/src/objects.js b/src/objects.js index 44f2716..c1ed200 100644 --- a/src/objects.js +++ b/src/objects.js @@ -135,10 +135,10 @@ export class TiledSprite extends Sprite { let copyUpByY = Math.ceil(this.y / this.image().height); let copyUpByX = Math.ceil(this.y / this.image().width); let copyDownByY = Math.ceil( - (context.canvas.height - this.y - this.image().height) / this.image().height, + (context.canvas.height - this.y - this.image().height) / this.image().height ); let copyDownByX = Math.ceil( - (context.canvas.width - this.y - this.image().width) / this.image().width, + (context.canvas.width - this.y - this.image().width) / this.image().width ); for (let iy = 0; iy <= copyUpByY; iy++) { @@ -163,12 +163,12 @@ export class TiledSprite extends Sprite { context.drawImage( this.image(), this.x + this.image().width * ix, - this.y - this.image().height * iy, + this.y - this.image().height * iy ); context.drawImage( this.image(), this.x - this.image().width * ix, - this.y - this.image().height * iy, + this.y - this.image().height * iy ); break; } @@ -197,12 +197,12 @@ export class TiledSprite extends Sprite { context.drawImage( this.image(), this.x + this.image().width * ix, - this.y + this.image().height * iy, + this.y + this.image().height * iy ); context.drawImage( this.image(), this.x - this.image().width * ix, - this.y + this.image().height * iy, + this.y + this.image().height * iy ); break; } diff --git a/src/scene.js b/src/scene.js index fb70c6d..4bcf846 100644 --- a/src/scene.js +++ b/src/scene.js @@ -54,7 +54,7 @@ export class SceneLayer { objects = Array(), options = { debug: false, - }, + } ) { // TODO: check types this.#objects = Array();