feat(#10): reset camera position after changing level
This commit is contained in:
parent
e2c439d1f3
commit
abf334607e
6 changed files with 47 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue