Files
esengine/source/src/ECS/Components/RenderableComponent.ts

56 lines
1.4 KiB
TypeScript
Raw Normal View History

2020-07-01 16:55:10 +08:00
///<reference path="./PooledComponent.ts" />
/**
*
*/
2020-07-01 14:19:40 +08:00
abstract class RenderableComponent extends PooledComponent implements IRenderable {
private _isVisible: boolean;
protected _areBoundsDirty = true;
2020-06-18 23:22:54 +08:00
protected _bounds: Rectangle = new Rectangle();
protected _localOffset: Vector2 = Vector2.zero;
2020-06-28 08:38:22 +08:00
public color: number = 0x000000;
public get width(){
return this.getWidth();
}
public get height(){
return this.getHeight();
}
public get isVisible(){
return this._isVisible;
}
public set isVisible(value: boolean){
this._isVisible = value;
if (this._isVisible)
this.onBecameVisible();
else
this.onBecameInvisible();
}
public get bounds(): Rectangle{
2020-06-29 15:41:02 +08:00
return new Rectangle(this.getBounds().x, this.getBounds().y, this.getBounds().width, this.getBounds().height);
}
protected getWidth(){
return this.bounds.width;
}
protected getHeight(){
return this.bounds.height;
}
protected onBecameVisible(){}
protected onBecameInvisible(){}
public abstract render(camera: Camera);
public isVisibleFromCamera(camera: Camera): boolean{
2020-07-01 14:19:40 +08:00
this.isVisible = camera.getBounds().intersects(this.getBounds());
2020-06-19 18:16:42 +08:00
return this.isVisible;
}
}