options for scenelayer

This commit is contained in:
Alexander Popov 2023-04-23 19:41:18 +03:00
parent 96c73f49be
commit d2ea90101b
Signed by: iiiypuk
GPG Key ID: E47FE0AB36CD5ED6
2 changed files with 15 additions and 3 deletions

View File

@ -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);

View File

@ -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);