feat(#10): allow multiple layers
This commit is contained in:
parent
1cac9b90bc
commit
e2c439d1f3
4 changed files with 112 additions and 101 deletions
|
@ -3,10 +3,18 @@ import { createCanvas } from "../utils.js";
|
|||
import { GameObject } from "./game-object.js";
|
||||
|
||||
export class Map extends GameObject {
|
||||
constructor({ name, imageId, elementId, selected = false, debug = false }) {
|
||||
constructor({
|
||||
name,
|
||||
imageId,
|
||||
elementId,
|
||||
layer = 0,
|
||||
selected = false,
|
||||
debug = false,
|
||||
}) {
|
||||
super({ debug });
|
||||
this.name = name;
|
||||
this.imageId = imageId;
|
||||
this.layer = layer;
|
||||
this.image = document.getElementById(imageId);
|
||||
this.imageWidth = this.image.width;
|
||||
this.imageHeight = this.image.height;
|
||||
|
@ -16,9 +24,11 @@ export class Map extends GameObject {
|
|||
}
|
||||
|
||||
async load() {
|
||||
const levelConfig = await fetch("/resources/" + this.name + ".json");
|
||||
this.levelConfig = await levelConfig.json();
|
||||
const layer = this.levelConfig.layers[0];
|
||||
const response = await fetch(`/resources/${this.name}.json`, {
|
||||
cache: "force-cache",
|
||||
});
|
||||
this.levelConfig = await response.json();
|
||||
const layer = this.levelConfig.layers[this.layer];
|
||||
const { data, height, width } = layer;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue