2020-06-08 16:23:48 +08:00
|
|
|
///<reference path="../Component.ts"/>
|
|
|
|
|
class Camera extends Component {
|
|
|
|
|
private _zoom;
|
|
|
|
|
private _origin: Vector2;
|
|
|
|
|
private _transformMatrix: Matrix2D = Matrix2D.identity;
|
|
|
|
|
private _inverseTransformMatrix = Matrix2D.identity;
|
2020-06-08 11:49:45 +08:00
|
|
|
|
2020-06-08 16:23:48 +08:00
|
|
|
public get transformMatrix(){
|
|
|
|
|
this.updateMatrixes();
|
|
|
|
|
|
|
|
|
|
return this._transformMatrix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
super();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public initialize() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public update(){
|
2020-06-08 23:04:57 +08:00
|
|
|
SceneManager.getActiveScene().entities.buffer.forEach(entity => entity.components.buffer.forEach(component => {
|
2020-06-08 16:23:48 +08:00
|
|
|
if (component.displayRender){
|
|
|
|
|
let has = this.entity.scene.$children.indexOf(component.displayRender)
|
|
|
|
|
if (has == -1){
|
|
|
|
|
this.entity.scene.stage.addChild(component.displayRender);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setPosition(position: Vector2){
|
|
|
|
|
this.entity.transform.setPosition(position);
|
|
|
|
|
|
|
|
|
|
return this;
|
2020-06-08 11:49:45 +08:00
|
|
|
}
|
|
|
|
|
|
2020-06-08 16:23:48 +08:00
|
|
|
public updateMatrixes(){
|
|
|
|
|
this._transformMatrix = Matrix2D.createTranslation(-this.entity.transform.position.x, -this.entity.transform.position.y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public destory() {
|
|
|
|
|
|
2020-06-08 11:49:45 +08:00
|
|
|
}
|
|
|
|
|
}
|