mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
Performance optimizations and refacturing.
This commit is contained in:
17
js/Camera.js
17
js/Camera.js
@@ -1,4 +1,5 @@
|
||||
import GeometryPoint from "./geometry/GeometryPoint.js";
|
||||
import GeometryRect from "./geometry/GeometryRect.js";
|
||||
|
||||
export default class Camera
|
||||
{
|
||||
@@ -114,4 +115,20 @@ export default class Camera
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getViewAsRect()
|
||||
{
|
||||
return new GeometryRect(this.position.x, this.position.y, this.width, this.height);
|
||||
}
|
||||
|
||||
isMovableInsideView(movable)
|
||||
{
|
||||
let viewRect = this.getViewAsRect();
|
||||
let distanceMovable = movable.getRect().getDiagonal().getLength() * 0.5;
|
||||
let distanceCamera = viewRect.getDiagonal().getLength() * 0.5;
|
||||
|
||||
let distanceMin = distanceMovable + distanceCamera;
|
||||
|
||||
return movable.getCenter().getDistanceToPoint(viewRect.getCenter()) < distanceMin;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user