修复demo 空格项目无法运行问题

This commit is contained in:
yhh
2020-09-14 17:59:03 +08:00
parent 24a463b85b
commit 4ce810bdcd
8 changed files with 15 additions and 6 deletions

View File

@@ -0,0 +1,37 @@
module samples {
import Component = es.Component;
import Vector2 = es.Vector2;
export class CameraBounds extends Component {
public min: Vector2;
public max: Vector2;
constructor(min: Vector2 = Vector2.zero, max: Vector2 = Vector2.zero){
super();
this.min = min;
this.max = max;
this.setUpdateOrder(Number.MAX_VALUE);
}
public onAddedToEntity(): void {
this.entity.updateOrder = Number.MAX_VALUE;
}
public update(): void {
let cameraBounds = this.entity.scene.camera.bounds;
if (cameraBounds.top < this.min.y)
this.entity.scene.camera.position.add(new Vector2(0, this.min.y - cameraBounds.top));
if (cameraBounds.left < this.min.x)
this.entity.scene.camera.position.add(new Vector2(this.min.x - cameraBounds.left, 0));
if (cameraBounds.bottom > this.max.y)
this.entity.scene.camera.position.add(new Vector2(0, this.max.y - cameraBounds.bottom));
if (cameraBounds.right > this.max.x)
this.entity.scene.camera.position.add(new Vector2(this.max.x - cameraBounds.right, 0));
}
}
}