mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
Camera implemented.
This commit is contained in:
@@ -42,7 +42,7 @@ export default class RetroAnimation extends RetroSprite
|
||||
}
|
||||
}
|
||||
|
||||
draw(context)
|
||||
draw(context, camera)
|
||||
{
|
||||
if (!this.isPlaying) {
|
||||
this.currentFrame = 0;
|
||||
@@ -54,8 +54,8 @@ export default class RetroAnimation extends RetroSprite
|
||||
0,
|
||||
this.frameWidth,
|
||||
this.canvas.height,
|
||||
this.position.x,
|
||||
this.position.y,
|
||||
this.position.x - camera.position.x,
|
||||
this.position.y - camera.position.y,
|
||||
this.frameWidth,
|
||||
this.canvas.height
|
||||
);
|
||||
|
||||
@@ -140,10 +140,15 @@ export default class RetroArchitecture
|
||||
return 0;
|
||||
}
|
||||
|
||||
draw(context)
|
||||
draw(context, camera = null)
|
||||
{
|
||||
for (let y = 0; y < this.rows; y++) {
|
||||
for (let x = 0; x < this.columns; x++) {
|
||||
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));
|
||||
|
||||
for (let y = viewY; y < viewHeight; y++) {
|
||||
for (let x = viewX; x < viewWidth; x++) {
|
||||
let field = this.matrix[y][x];
|
||||
|
||||
if (field !== null) {
|
||||
@@ -153,8 +158,8 @@ export default class RetroArchitecture
|
||||
0,
|
||||
this.tileWidth,
|
||||
this.tileHeight,
|
||||
x * this.tileWidth,
|
||||
y * this.tileHeight,
|
||||
x * this.tileWidth - camera.position.x,
|
||||
y * this.tileHeight - camera.position.y,
|
||||
this.tileWidth,
|
||||
this.tileHeight
|
||||
);
|
||||
|
||||
@@ -61,9 +61,9 @@ export default class RetroSprite
|
||||
return new GeometryPoint(this.position.x + this.getWidth() * 0.5, this.position.y);
|
||||
}
|
||||
|
||||
draw(context)
|
||||
draw(context, camera)
|
||||
{
|
||||
context.drawImage(this.canvas, this.position.x, this.position.y);
|
||||
context.drawImage(this.canvas, this.position.x - camera.position.x, this.position.y - camera.position.y);
|
||||
}
|
||||
|
||||
hasRectCollisionWith(sprite)
|
||||
|
||||
Reference in New Issue
Block a user