2020-06-23 09:10:40 +08:00
|
|
|
class PostProcessor {
|
|
|
|
|
public enable: boolean;
|
|
|
|
|
public effect: egret.CustomFilter;
|
|
|
|
|
public scene: Scene;
|
|
|
|
|
public shape: egret.Shape;
|
|
|
|
|
|
|
|
|
|
constructor(effect: egret.CustomFilter = null){
|
2020-06-23 16:18:14 +08:00
|
|
|
this.enable = true;
|
2020-06-23 09:10:40 +08:00
|
|
|
this.effect = effect;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public onAddedToScene(scene: Scene){
|
|
|
|
|
this.scene = scene;
|
|
|
|
|
this.shape = new egret.Shape();
|
|
|
|
|
scene.addChild(this.shape);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public process(source: egret.DisplayObject){
|
|
|
|
|
this.drawFullscreenQuad(source, this.effect);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-23 16:18:14 +08:00
|
|
|
public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number){}
|
|
|
|
|
|
2020-06-23 09:10:40 +08:00
|
|
|
protected drawFullscreenQuad(texture: egret.DisplayObject, effect: egret.CustomFilter = null){
|
2020-06-23 16:18:14 +08:00
|
|
|
texture.filters = [effect];
|
2020-06-23 09:10:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public unload(){
|
|
|
|
|
if (this.effect){
|
|
|
|
|
this.effect = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.scene.removeChild(this.shape);
|
2020-06-23 16:18:14 +08:00
|
|
|
this.scene = null;
|
2020-06-23 09:10:40 +08:00
|
|
|
}
|
|
|
|
|
}
|