相机渲染
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
///<reference path="../Component.ts"/>
|
||||
class Camera extends Component {
|
||||
private _zoom;
|
||||
private _origin: Vector2;
|
||||
private _origin: Vector2 = Vector2.zero;
|
||||
private _transformMatrix: Matrix2D = Matrix2D.identity;
|
||||
private _inverseTransformMatrix = Matrix2D.identity;
|
||||
private _projectionMatrix = Matrix2D.identity;
|
||||
|
||||
private _minimumZoom = 0.3;
|
||||
private _maximumZoom = 3;
|
||||
private _areMatrixesDirty = true;
|
||||
private _inset: CameraInset;
|
||||
private _bounds: Rectangle;
|
||||
private _inset: CameraInset = new CameraInset();
|
||||
private _bounds: Rectangle = new Rectangle();
|
||||
private _areBoundsDirty = true;
|
||||
private _isProjectionMatrixDirty = true;
|
||||
|
||||
public get bounds(){
|
||||
if (this._areMatrixesDirty)
|
||||
@@ -104,6 +106,14 @@ class Camera extends Component {
|
||||
this.setZoom(0);
|
||||
}
|
||||
|
||||
public onSceneSizeChanged(newWidth: number, newHeight: number){
|
||||
this._isProjectionMatrixDirty = true;
|
||||
let oldOrigin = this._origin;
|
||||
this.origin = new Vector2(newWidth / 2, newHeight / 2);
|
||||
|
||||
this.entity.transform.position = Vector2.add(this.entity.transform.position, Vector2.subtract(this._origin, oldOrigin));
|
||||
}
|
||||
|
||||
public setMinimumZoom(minZoom: number): Camera{
|
||||
if (this._zoom < minZoom)
|
||||
this._zoom = this.minimumZoom;
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
abstract class RenderableComponent extends Component implements IRenderable {
|
||||
private _isVisible: boolean;
|
||||
protected _areBoundsDirty = true;
|
||||
protected _bounds: Rectangle;
|
||||
protected _localOffset: Vector2;
|
||||
protected _bounds: Rectangle = new Rectangle();
|
||||
protected _localOffset: Vector2 = Vector2.zero;
|
||||
|
||||
public get width(){
|
||||
return this.getWidth();
|
||||
@@ -57,8 +57,10 @@ abstract class RenderableComponent extends Component implements IRenderable {
|
||||
public abstract render(camera: Camera);
|
||||
|
||||
public isVisibleFromCamera(camera: Camera): boolean{
|
||||
this.isVisible = camera.bounds.intersects(this.bounds);
|
||||
return this.isVisible;
|
||||
// this.isVisible = camera.bounds.intersects(this.bounds);
|
||||
// return this.isVisible;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public onEntityTransformChanged(comp: ComponentTransform){
|
||||
|
||||
@@ -2,7 +2,7 @@ class SpriteRenderer extends RenderableComponent {
|
||||
private _sprite: egret.DisplayObject;
|
||||
private _origin: Vector2;
|
||||
|
||||
public get bounds(){
|
||||
protected getBounds(){
|
||||
if (this._areBoundsDirty){
|
||||
if (this._sprite){
|
||||
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin,
|
||||
|
||||
Reference in New Issue
Block a user