feat(#10): reset camera position after changing level

This commit is contained in:
Juan Sebastián Montoya 2024-09-14 23:51:24 -05:00
parent e2c439d1f3
commit abf334607e
6 changed files with 47 additions and 2 deletions

View file

@ -29,7 +29,7 @@ export class Map extends GameObject {
});
this.levelConfig = await response.json();
const layer = this.levelConfig.layers[this.layer];
const { data, height, width } = layer;
const { data, height, width } = layer ?? {};
this.width = width;
this.height = height;
this.data = data;
@ -39,6 +39,9 @@ export class Map extends GameObject {
if (this._level) {
return this._level;
}
if (!this.width || !this.height) {
return null;
}
const { ctx, canvas } = createCanvas(
this.width * TILE_SIZE,
this.height * TILE_SIZE
@ -84,7 +87,7 @@ export class Map extends GameObject {
}
render(ctx, sourceX, sourceY, width, height) {
if (!this.levelConfig || !this.selected) {
if (!this.levelConfig || !this.selected || !this.level) {
return;
}