fps delta move to Settings

This commit is contained in:
Alexander Popov 2023-12-01 15:55:39 +03:00
parent ddbde3a954
commit 0ca82b9564
Signed by: iiiypuk
GPG Key ID: E47FE0AB36CD5ED6
3 changed files with 12 additions and 11 deletions

View File

@ -12,7 +12,7 @@ export class App {
options = { options = {
backgroundColor: '#ffcc68', backgroundColor: '#ffcc68',
welcome: true, welcome: true,
}, }
) { ) {
this.#version = 'beeeeeeta'; this.#version = 'beeeeeeta';
@ -31,7 +31,7 @@ export class App {
} }
this.scene = new Scene(this.canvas, this.context, w, h); this.scene = new Scene(this.canvas, this.context, w, h);
this.prevTime = Date.now(); Settings.prevTime = Date.now();
const logStrings = [ const logStrings = [
'ujs engine', 'ujs engine',
@ -51,9 +51,10 @@ export class App {
} }
run = () => { run = () => {
// Calculating FPS
let newTime = Date.now(); let newTime = Date.now();
Settings.delta = (newTime - this.prevTime) / 1000; Settings.delta = (newTime - Settings.prevTime) / 1000;
this.prevTime = newTime; Settings.prevTime = newTime;
// 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);

View File

@ -135,10 +135,10 @@ export class TiledSprite extends Sprite {
let copyUpByY = Math.ceil(this.y / this.image().height); let copyUpByY = Math.ceil(this.y / this.image().height);
let copyUpByX = Math.ceil(this.y / this.image().width); let copyUpByX = Math.ceil(this.y / this.image().width);
let copyDownByY = Math.ceil( 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( 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++) { for (let iy = 0; iy <= copyUpByY; iy++) {
@ -163,12 +163,12 @@ export class TiledSprite extends Sprite {
context.drawImage( context.drawImage(
this.image(), this.image(),
this.x + this.image().width * ix, this.x + this.image().width * ix,
this.y - this.image().height * iy, this.y - this.image().height * iy
); );
context.drawImage( context.drawImage(
this.image(), this.image(),
this.x - this.image().width * ix, this.x - this.image().width * ix,
this.y - this.image().height * iy, this.y - this.image().height * iy
); );
break; break;
} }
@ -197,12 +197,12 @@ export class TiledSprite extends Sprite {
context.drawImage( context.drawImage(
this.image(), this.image(),
this.x + this.image().width * ix, this.x + this.image().width * ix,
this.y + this.image().height * iy, this.y + this.image().height * iy
); );
context.drawImage( context.drawImage(
this.image(), this.image(),
this.x - this.image().width * ix, this.x - this.image().width * ix,
this.y + this.image().height * iy, this.y + this.image().height * iy
); );
break; break;
} }

View File

@ -54,7 +54,7 @@ export class SceneLayer {
objects = Array(), objects = Array(),
options = { options = {
debug: false, debug: false,
}, }
) { ) {
// TODO: check types // TODO: check types
this.#objects = Array(); this.#objects = Array();