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

59 lines
1.4 KiB
TypeScript
Raw Normal View History

/**
*
*/
abstract class RenderableComponent extends Component 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-06-19 18:16:42 +08:00
this.isVisible = camera.bounds.intersects(this.bounds);
return this.isVisible;
}
public onEntityTransformChanged(comp: ComponentTransform){
this._areBoundsDirty = true;
}
}