Loading of levels is working now

This commit is contained in:
Mal
2023-09-18 22:33:55 +02:00
parent 349792f916
commit aeece9731c
11 changed files with 347 additions and 271 deletions

View File

@@ -204,10 +204,10 @@ export default class RetroArchitecture
draw(context, camera = new Camera())
{
let viewX = parseInt(Math.floor(Math.max(0, camera.position.x) / this.tileWidth));
let viewWidth = parseInt(Math.min(Math.ceil(camera.width), this.columns));
let viewY = parseInt(Math.floor(Math.max(0, camera.position.y)) / this.tileHeight);
let viewHeight = parseInt(Math.min(Math.ceil(camera.height), this.rows));
const viewX = parseInt(Math.floor(Math.max(0, camera.position.x) / this.tileWidth));
const viewWidth = parseInt(Math.min(Math.ceil(camera.width), this.columns));
const viewY = parseInt(Math.floor(Math.max(0, camera.position.y)) / this.tileHeight);
const viewHeight = parseInt(Math.min(Math.ceil(camera.height), this.rows));
for (let y = viewY; y < viewHeight; y++) {
for (let x = viewX; x < viewWidth; x++) {
@@ -235,6 +235,11 @@ export default class RetroArchitecture
);
}
getStartPosition()
{
return new GeometryPoint(this.startX * this.tileWidth, this.startY * this.tileHeight);
}
static createFromData(level)
{
let graphicSet = GraphicSet[level.getTilesetId()];

View File

@@ -82,7 +82,7 @@ export default class RetroSprite
canvasTemp.width = this.image.width * this.scale;
canvasTemp.height = this.image.height * this.scale;
let contextTemp = canvasTemp.getContext('2d');
let contextTemp = canvasTemp.getContext('2d', {willReadFrequently: true});
contextTemp.drawImage(this.image, 0, 0);
this.canvas.width = this.image.width * this.scale;
@@ -99,4 +99,4 @@ export default class RetroSprite
}
}
}
}
}