新增postProcessor用于处理屏幕特效

This commit is contained in:
YHH
2020-06-23 09:10:40 +08:00
parent fb5906afe0
commit 795bfab1aa
11 changed files with 284 additions and 22 deletions

View File

@@ -0,0 +1,37 @@
class PostProcessor {
public enable: boolean;
public effect: egret.CustomFilter;
public scene: Scene;
public shape: egret.Shape;
constructor(effect: egret.CustomFilter = null){
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);
}
protected drawFullscreenQuad(texture: egret.DisplayObject, effect: egret.CustomFilter = null){
this.shape.graphics.clear();
this.shape.graphics.beginFill(0x000000, 1);
this.shape.graphics.drawRect(0, 0, texture.width, texture.height);
this.shape.graphics.endFill();
this.shape.filters = [effect];
}
public unload(){
if (this.effect){
this.effect = null;
}
this.scene = null;
this.scene.removeChild(this.shape);
}
}