新增windtransition
This commit is contained in:
@@ -61,4 +61,15 @@ abstract class SceneTransition {
|
||||
SceneManager.scene = this.sceneLoadAction();
|
||||
this.isNewSceneLoaded = true;
|
||||
}
|
||||
|
||||
public tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection = false){
|
||||
return new Promise((resolve)=>{
|
||||
let start = reverseDirection ? 1 : 0;
|
||||
let end = reverseDirection ? 0 : 1;
|
||||
|
||||
egret.Tween.get(filter.uniforms).set({_progress: start}).to({_progress: end}, duration * 1000, easeType).call(()=>{
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
66
source/src/Graphics/Transitions/WindTransition.ts
Normal file
66
source/src/Graphics/Transitions/WindTransition.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
class WindTransition extends SceneTransition {
|
||||
private _mask: egret.Shape;
|
||||
private _windEffect: egret.CustomFilter;
|
||||
|
||||
public duration = 1;
|
||||
public set windSegments(value: number) {
|
||||
this._windEffect.uniforms._windSegments = value;
|
||||
}
|
||||
public set size(value: number) {
|
||||
this._windEffect.uniforms._size = value;
|
||||
}
|
||||
public easeType = egret.Ease.quadOut;
|
||||
constructor(sceneLoadAction: Function) {
|
||||
super(sceneLoadAction);
|
||||
|
||||
let vertexSrc = "attribute vec2 aVertexPosition;\n" +
|
||||
"attribute vec2 aTextureCoord;\n" +
|
||||
|
||||
"uniform vec2 projectionVector;\n" +
|
||||
|
||||
"varying vec2 vTextureCoord;\n" +
|
||||
|
||||
"const vec2 center = vec2(-1.0, 1.0);\n" +
|
||||
|
||||
"void main(void) {\n" +
|
||||
" gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" +
|
||||
" vTextureCoord = aTextureCoord;\n" +
|
||||
"}";
|
||||
let fragmentSrc = "precision lowp float;\n" +
|
||||
"varying vec2 vTextureCoord;\n" +
|
||||
"uniform sampler2D uSampler;\n" +
|
||||
"uniform float _progress;\n" +
|
||||
"uniform float _size;\n" +
|
||||
"uniform float _windSegments;\n" +
|
||||
|
||||
"void main(void) {\n" +
|
||||
"vec2 co = floor(vec2(0.0, vTextureCoord.y * _windSegments));\n" +
|
||||
"float x = sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453;\n" +
|
||||
"float r = x - floor(x);\n" +
|
||||
"float m = smoothstep(0.0, -_size, vTextureCoord.x * (1.0 - _size) + _size * r - (_progress * (1.0 + _size)));\n" +
|
||||
"vec4 fg = texture2D(uSampler, vTextureCoord);\n" +
|
||||
"gl_FragColor = mix(fg, vec4(0, 0, 0, 0), m);\n" +
|
||||
"}";
|
||||
|
||||
this._windEffect = new egret.CustomFilter(vertexSrc, fragmentSrc, {
|
||||
_progress: 0,
|
||||
_size: 0.3,
|
||||
_windSegments: 100
|
||||
});
|
||||
|
||||
this._mask = new egret.Shape();
|
||||
this._mask.graphics.beginFill(0xFFFFFF, 1);
|
||||
this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
|
||||
this._mask.graphics.endFill();
|
||||
this._mask.filters = [this._windEffect];
|
||||
SceneManager.stage.addChild(this._mask);
|
||||
}
|
||||
|
||||
public onBeginTransition() {
|
||||
this.loadNextScene();
|
||||
this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType).then(()=>{
|
||||
this.transitionComplete();
|
||||
SceneManager.stage.removeChild(this._mask);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user