From d2ea90101b0b00ead15dd5c67b44ed71551a417a Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Sun, 23 Apr 2023 19:41:18 +0300 Subject: [PATCH] options for scenelayer --- src/js/game.example.js | 2 +- src/js/scene.js | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/js/game.example.js b/src/js/game.example.js index 2262686..593b606 100644 --- a/src/js/game.example.js +++ b/src/js/game.example.js @@ -25,7 +25,7 @@ let layerHud = new SceneLayer('hud', [ new Sprite('compass-arrow.png', 27, 21), ]); -let layerInstances = new SceneLayer('Instances', [Player.rect]); +let layerInstances = new SceneLayer('Instances', [Player.rect], { debug: true }); // init app let app = new App(document.querySelector('canvas'), 400, 400); diff --git a/src/js/scene.js b/src/js/scene.js index a29c013..187d191 100644 --- a/src/js/scene.js +++ b/src/js/scene.js @@ -21,7 +21,7 @@ export class Scene { } if (typeof item.draw == 'function') { - item.draw(this.#context, true); + item.draw(this.#context, layer.options.debug); } else { console.log(`⛔ Error display '${item.constructor.name}' object.`); } @@ -47,9 +47,21 @@ export class Scene { export class SceneLayer { #objects; - constructor(name, objects = Array()) { + constructor( + name, + objects = Array(), + options = { + debug: false, + } + ) { // TODO: check types this.#objects = Array(); + this.options = options; + + // check options || FIXIT: + if (typeof this.options.debug === 'undefined') { + this.options.debug = false; + } objects.forEach((object) => { this.#objects.push(object);