全部移动至es模块

This commit is contained in:
yhh
2020-07-23 11:00:46 +08:00
parent 814234ca61
commit 1b52bc5fd1
71 changed files with 19273 additions and 16907 deletions

View File

@@ -1,72 +1,74 @@
class GaussianBlurEffect extends egret.CustomFilter {
// private static blur_frag = "precision mediump float;\n" +
// "uniform vec2 blur;\n" +
// "uniform sampler2D uSampler;\n" +
// "varying vec2 vTextureCoord;\n" +
// "uniform vec2 uTextureSize;\n" +
// "void main()\n" +
// "{\n " +
// "const int sampleRadius = 5;\n" +
// "const int samples = sampleRadius * 2 + 1;\n" +
// "vec2 blurUv = blur / uTextureSize;\n" +
// "vec4 color = vec4(0, 0, 0, 0);\n" +
// "vec2 uv = vec2(0.0, 0.0);\n" +
// "blurUv /= float(sampleRadius);\n" +
// "for (int i = -sampleRadius; i <= sampleRadius; i++) {\n" +
// "uv.x = vTextureCoord.x + float(i) * blurUv.x;\n" +
// "uv.y = vTextureCoord.y + float(i) * blurUv.y;\n" +
// "color += texture2D(uSampler, uv);\n" +
// "}\n" +
// "color /= float(samples);\n" +
// "gl_FragColor = color;\n" +
// "}";
module es {
export class GaussianBlurEffect extends egret.CustomFilter {
// private static blur_frag = "precision mediump float;\n" +
// "uniform vec2 blur;\n" +
// "uniform sampler2D uSampler;\n" +
// "varying vec2 vTextureCoord;\n" +
// "uniform vec2 uTextureSize;\n" +
// "void main()\n" +
// "{\n " +
// "const int sampleRadius = 5;\n" +
// "const int samples = sampleRadius * 2 + 1;\n" +
// "vec2 blurUv = blur / uTextureSize;\n" +
// "vec4 color = vec4(0, 0, 0, 0);\n" +
// "vec2 uv = vec2(0.0, 0.0);\n" +
// "blurUv /= float(sampleRadius);\n" +
private static blur_frag = "precision mediump float;\n" +
"uniform sampler2D uSampler;\n" +
"uniform float screenWidth;\n" +
"uniform float screenHeight;\n" +
// "for (int i = -sampleRadius; i <= sampleRadius; i++) {\n" +
// "uv.x = vTextureCoord.x + float(i) * blurUv.x;\n" +
// "uv.y = vTextureCoord.y + float(i) * blurUv.y;\n" +
// "color += texture2D(uSampler, uv);\n" +
// "}\n" +
"float normpdf(in float x, in float sigma)\n" +
"{\n" +
"return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n" +
"}\n" +
// "color /= float(samples);\n" +
// "gl_FragColor = color;\n" +
// "}";
"void main()\n" +
"{\n" +
"vec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\n" +
private static blur_frag = "precision mediump float;\n" +
"uniform sampler2D uSampler;\n" +
"uniform float screenWidth;\n" +
"uniform float screenHeight;\n" +
"const int mSize = 11;\n" +
"const int kSize = (mSize - 1)/2;\n" +
"float kernel[mSize];\n" +
"vec3 final_colour = vec3(0.0);\n" +
"float normpdf(in float x, in float sigma)\n" +
"{\n" +
"return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n" +
"}\n" +
"float sigma = 7.0;\n" +
"float z = 0.0;\n" +
"for (int j = 0; j <= kSize; ++j)\n" +
"{\n" +
"kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n" +
"}\n" +
"for (int j = 0; j < mSize; ++j)\n" +
"{\n" +
"z += kernel[j];\n" +
"}\n" +
"void main()\n" +
"{\n" +
"vec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\n" +
"for (int i = -kSize; i <= kSize; ++i)\n" +
"{\n" +
"for (int j = -kSize; j <= kSize; ++j)\n" +
"{\n" +
"final_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n" +
"}\n}\n" +
"gl_FragColor = vec4(final_colour/(z*z), 1.0);\n" +
"}";
"const int mSize = 11;\n" +
"const int kSize = (mSize - 1)/2;\n" +
"float kernel[mSize];\n" +
"vec3 final_colour = vec3(0.0);\n" +
constructor(){
super(PostProcessor.default_vert, GaussianBlurEffect.blur_frag,{
screenWidth: SceneManager.stage.stageWidth,
screenHeight: SceneManager.stage.stageHeight
});
"float sigma = 7.0;\n" +
"float z = 0.0;\n" +
"for (int j = 0; j <= kSize; ++j)\n" +
"{\n" +
"kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n" +
"}\n" +
"for (int j = 0; j < mSize; ++j)\n" +
"{\n" +
"z += kernel[j];\n" +
"}\n" +
"for (int i = -kSize; i <= kSize; ++i)\n" +
"{\n" +
"for (int j = -kSize; j <= kSize; ++j)\n" +
"{\n" +
"final_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n" +
"}\n}\n" +
"gl_FragColor = vec4(final_colour/(z*z), 1.0);\n" +
"}";
constructor(){
super(PostProcessor.default_vert, GaussianBlurEffect.blur_frag,{
screenWidth: SceneManager.stage.stageWidth,
screenHeight: SceneManager.stage.stageHeight
});
}
}
}
}

View File

@@ -1,34 +1,36 @@
class PolygonLightEffect extends egret.CustomFilter {
private static vertSrc = "attribute vec2 aVertexPosition;\n" +
"attribute vec2 aTextureCoord;\n" +
module es {
export class PolygonLightEffect extends egret.CustomFilter {
private static vertSrc = "attribute vec2 aVertexPosition;\n" +
"attribute vec2 aTextureCoord;\n" +
"uniform vec2 projectionVector;\n" +
"uniform vec2 projectionVector;\n" +
"varying vec2 vTextureCoord;\n" +
"varying vec2 vTextureCoord;\n" +
"const vec2 center = vec2(-1.0, 1.0);\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" +
"}";
private static fragmentSrc = "precision lowp float;\n" +
"varying vec2 vTextureCoord;\n" +
"uniform sampler2D uSampler;\n" +
"void main(void) {\n" +
" gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" +
" vTextureCoord = aTextureCoord;\n" +
"}";
private static fragmentSrc = "precision lowp float;\n" +
"varying vec2 vTextureCoord;\n" +
"uniform sampler2D uSampler;\n" +
"#define SAMPLE_COUNT 15\n" +
"#define SAMPLE_COUNT 15\n" +
"uniform vec2 _sampleOffsets[SAMPLE_COUNT];\n" +
"uniform float _sampleWeights[SAMPLE_COUNT];\n" +
"uniform vec2 _sampleOffsets[SAMPLE_COUNT];\n" +
"uniform float _sampleWeights[SAMPLE_COUNT];\n" +
"void main(void) {\n" +
"vec4 c = vec4(0, 0, 0, 0);\n" +
"for( int i = 0; i < SAMPLE_COUNT; i++ )\n" +
" c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\n" +
"gl_FragColor = c;\n" +
"}";
"void main(void) {\n" +
"vec4 c = vec4(0, 0, 0, 0);\n" +
"for( int i = 0; i < SAMPLE_COUNT; i++ )\n" +
" c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\n" +
"gl_FragColor = c;\n" +
"}";
constructor(){
super(PolygonLightEffect.vertSrc, PolygonLightEffect.fragmentSrc);
constructor(){
super(PolygonLightEffect.vertSrc, PolygonLightEffect.fragmentSrc);
}
}
}
}

View File

@@ -1,27 +1,29 @@
class GraphicsCapabilities extends egret.Capabilities {
module es {
export class GraphicsCapabilities extends egret.Capabilities {
public initialize(device: GraphicsDevice){
this.platformInitialize(device);
}
private platformInitialize(device: GraphicsDevice){
let capabilities = this;
capabilities["isMobile"] = true;
let systemInfo = wx.getSystemInfoSync();
let systemStr = systemInfo.system.toLowerCase();
if (systemStr.indexOf("ios") > -1){
capabilities["os"] = "iOS";
} else if(systemStr.indexOf("android") > -1){
capabilities["os"] = "Android";
public initialize(device: GraphicsDevice){
this.platformInitialize(device);
}
let language = systemInfo.language;
if (language.indexOf('zh') > -1){
language = "zh-CN";
} else {
language = "en-US";
private platformInitialize(device: GraphicsDevice){
let capabilities = this;
capabilities["isMobile"] = true;
let systemInfo = wx.getSystemInfoSync();
let systemStr = systemInfo.system.toLowerCase();
if (systemStr.indexOf("ios") > -1){
capabilities["os"] = "iOS";
} else if(systemStr.indexOf("android") > -1){
capabilities["os"] = "Android";
}
let language = systemInfo.language;
if (language.indexOf('zh') > -1){
language = "zh-CN";
} else {
language = "en-US";
}
capabilities["language"] = language;
}
capabilities["language"] = language;
}
}
}

View File

@@ -1,10 +1,12 @@
class GraphicsDevice {
private viewport: Viewport;
module es {
export class GraphicsDevice {
private viewport: Viewport;
public graphicsCapabilities: GraphicsCapabilities;
public graphicsCapabilities: GraphicsCapabilities;
constructor(){
this.graphicsCapabilities = new GraphicsCapabilities();
this.graphicsCapabilities.initialize(this);
constructor(){
this.graphicsCapabilities = new GraphicsCapabilities();
this.graphicsCapabilities.initialize(this);
}
}
}
}

View File

@@ -1,58 +1,60 @@
class PostProcessor {
public enabled: boolean;
public effect: egret.Filter;
public scene: Scene;
public shape: egret.Shape;
module es {
export class PostProcessor {
public enabled: boolean;
public effect: egret.Filter;
public scene: Scene;
public shape: egret.Shape;
public static default_vert = "attribute vec2 aVertexPosition;\n" +
"attribute vec2 aTextureCoord;\n" +
"attribute vec2 aColor;\n" +
"uniform vec2 projectionVector;\n" +
//"uniform vec2 offsetVector;\n" +
public static default_vert = "attribute vec2 aVertexPosition;\n" +
"attribute vec2 aTextureCoord;\n" +
"attribute vec2 aColor;\n" +
"varying vec2 vTextureCoord;\n" +
"varying vec4 vColor;\n" +
"uniform vec2 projectionVector;\n" +
//"uniform vec2 offsetVector;\n" +
"const vec2 center = vec2(-1.0, 1.0);\n" +
"varying vec2 vTextureCoord;\n" +
"varying vec4 vColor;\n" +
"void main(void) {\n" +
"gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" +
"vTextureCoord = aTextureCoord;\n" +
"vColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n" +
"}";
"const vec2 center = vec2(-1.0, 1.0);\n" +
constructor(effect: egret.Filter = null){
this.enabled = true;
this.effect = effect;
}
"void main(void) {\n" +
"gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" +
"vTextureCoord = aTextureCoord;\n" +
"vColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n" +
"}";
public onAddedToScene(scene: Scene){
this.scene = scene;
this.shape = new egret.Shape();
this.shape.graphics.beginFill(0xFFFFFF, 1);
this.shape.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
this.shape.graphics.endFill();
scene.addChild(this.shape);
}
public process(){
this.drawFullscreenQuad();
}
public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number){}
protected drawFullscreenQuad(){
this.scene.filters = [this.effect];
// this.shape.filters = [this.effect];
}
public unload(){
if (this.effect){
this.effect = null;
constructor(effect: egret.Filter = null){
this.enabled = true;
this.effect = effect;
}
this.scene.removeChild(this.shape);
this.scene = null;
public onAddedToScene(scene: Scene){
this.scene = scene;
this.shape = new egret.Shape();
this.shape.graphics.beginFill(0xFFFFFF, 1);
this.shape.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
this.shape.graphics.endFill();
scene.addChild(this.shape);
}
public process(){
this.drawFullscreenQuad();
}
public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number){}
protected drawFullscreenQuad(){
this.scene.filters = [this.effect];
// this.shape.filters = [this.effect];
}
public unload(){
if (this.effect){
this.effect = null;
}
this.scene.removeChild(this.shape);
this.scene = null;
}
}
}
}

View File

@@ -1,6 +1,8 @@
class GaussianBlurPostProcessor extends PostProcessor {
public onAddedToScene(scene: Scene){
super.onAddedToScene(scene);
this.effect = new GaussianBlurEffect();
module es {
export class GaussianBlurPostProcessor extends PostProcessor {
public onAddedToScene(scene: Scene){
super.onAddedToScene(scene);
this.effect = new GaussianBlurEffect();
}
}
}
}

View File

@@ -1,13 +1,15 @@
///<reference path="./Renderer.ts" />
class DefaultRenderer extends Renderer {
public render(scene: Scene) {
let cam = this.camera ? this.camera : scene.camera;
this.beginRender(cam);
module es {
export class DefaultRenderer extends Renderer {
public render(scene: Scene) {
let cam = this.camera ? this.camera : scene.camera;
this.beginRender(cam);
for (let i = 0; i < scene.renderableComponents.count; i++){
let renderable = scene.renderableComponents.buffer[i];
if (renderable.enabled && renderable.isVisibleFromCamera(cam))
this.renderAfterStateCheck(renderable, cam);
for (let i = 0; i < scene.renderableComponents.count; i++){
let renderable = scene.renderableComponents.buffer[i];
if (renderable.enabled && renderable.isVisibleFromCamera(cam))
this.renderAfterStateCheck(renderable, cam);
}
}
}
}
}

View File

@@ -1,46 +1,48 @@
class PolyLight extends RenderableComponent {
public power: number;
protected _radius: number;
private _lightEffect;
private _indices: number[] = [];
module es {
export class PolyLight extends RenderableComponent {
public power: number;
protected _radius: number;
private _lightEffect;
private _indices: number[] = [];
public get radius(){
return this._radius;
}
public set radius(value: number){
this.setRadius(value);
}
public get radius(){
return this._radius;
}
public set radius(value: number){
this.setRadius(value);
}
constructor(radius: number, color: number, power: number){
super();
constructor(radius: number, color: number, power: number){
super();
this.radius = radius;
this.power = power;
this.color = color;
this.computeTriangleIndices();
}
this.radius = radius;
this.power = power;
this.color = color;
this.computeTriangleIndices();
}
private computeTriangleIndices(totalTris: number = 20){
this._indices.length = 0;
private computeTriangleIndices(totalTris: number = 20){
this._indices.length = 0;
for (let i = 0; i < totalTris; i += 2){
this._indices.push(0);
this._indices.push(i + 2);
this._indices.push(i + 1);
}
}
public setRadius(radius: number){
if (radius != this._radius){
this._radius = radius;
this._areBoundsDirty = true;
}
}
public render(camera: Camera) {
}
public reset(){
for (let i = 0; i < totalTris; i += 2){
this._indices.push(0);
this._indices.push(i + 2);
this._indices.push(i + 1);
}
}
public setRadius(radius: number){
if (radius != this._radius){
this._radius = radius;
this._areBoundsDirty = true;
}
}
public render(camera: Camera) {
}
public reset(){
}
}
}

View File

@@ -1,38 +1,40 @@
/**
* 渲染器被添加到场景中并处理所有对RenderableComponent的实际调用
*/
abstract class Renderer {
/**
* 渲染器用于渲染的摄像机(实际上是用于剔除的变换矩阵和边界)
* 不是必须的
* Renderer子类可以选择调用beginRender时使用的摄像头
*/
public camera: Camera;
module es {
/**
* 渲染器被添加到场景调用
* @param scene
* 渲染器被添加到场景中并处理所有对RenderableComponent的实际调用
*/
public onAddedToScene(scene: Scene){}
export abstract class Renderer {
/**
* 渲染器用于渲染的摄像机(实际上是用于剔除的变换矩阵和边界)
* 不是必须的
* Renderer子类可以选择调用beginRender时使用的摄像头
*/
public camera: Camera;
protected beginRender(cam: Camera){
/**
* 当渲染器被添加到场景时调用
* @param scene
*/
public onAddedToScene(scene: Scene){}
protected beginRender(cam: Camera){
}
/**
*
* @param scene
*/
public abstract render(scene: Scene);
public unload(){ }
/**
*
* @param renderable
* @param cam
*/
protected renderAfterStateCheck(renderable: IRenderable, cam: Camera){
renderable.render(cam);
}
}
/**
*
* @param scene
*/
public abstract render(scene: Scene);
public unload(){ }
/**
*
* @param renderable
* @param cam
*/
protected renderAfterStateCheck(renderable: IRenderable, cam: Camera){
renderable.render(cam);
}
}
}

View File

@@ -1,7 +1,9 @@
/**
* 渲染器使用自己的不移动的摄像机进行渲染。
*/
class ScreenSpaceRenderer extends Renderer {
public render(scene: Scene) {
module es {
/**
* 渲染器使用自己的不移动的摄像机进行渲染。
*/
export class ScreenSpaceRenderer extends Renderer {
public render(scene: Scene) {
}
}
}
}

View File

@@ -1,38 +1,40 @@
///<reference path="./SceneTransition.ts"/>
class FadeTransition extends SceneTransition {
public fadeToColor: number = 0x000000;
public fadeOutDuration = 0.4;
public fadeEaseType: Function = egret.Ease.quadInOut;
public delayBeforeFadeInDuration = 0.1;
private _mask: egret.Shape;
private _alpha: number = 0;
module es {
export class FadeTransition extends SceneTransition {
public fadeToColor: number = 0x000000;
public fadeOutDuration = 0.4;
public fadeEaseType: Function = egret.Ease.quadInOut;
public delayBeforeFadeInDuration = 0.1;
private _mask: egret.Shape;
private _alpha: number = 0;
constructor(sceneLoadAction: Function) {
super(sceneLoadAction);
this._mask = new egret.Shape();
}
constructor(sceneLoadAction: Function) {
super(sceneLoadAction);
this._mask = new egret.Shape();
}
public async onBeginTransition() {
this._mask.graphics.beginFill(this.fadeToColor, 1);
this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
this._mask.graphics.endFill();
SceneManager.stage.addChild(this._mask);
public async onBeginTransition() {
this._mask.graphics.beginFill(this.fadeToColor, 1);
this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
this._mask.graphics.endFill();
SceneManager.stage.addChild(this._mask);
egret.Tween.get(this).to({ _alpha: 1}, this.fadeOutDuration * 1000, this.fadeEaseType)
.call(async () => {
await this.loadNextScene();
}).wait(this.delayBeforeFadeInDuration).call(() => {
egret.Tween.get(this).to({ _alpha: 1}, this.fadeOutDuration * 1000, this.fadeEaseType)
.call(async () => {
await this.loadNextScene();
}).wait(this.delayBeforeFadeInDuration).call(() => {
egret.Tween.get(this).to({ _alpha: 0 }, this.fadeOutDuration * 1000, this.fadeEaseType).call(() => {
this.transitionComplete();
SceneManager.stage.removeChild(this._mask);
});
});
}
}
public render(){
this._mask.graphics.clear();
this._mask.graphics.beginFill(this.fadeToColor, this._alpha);
this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
this._mask.graphics.endFill();
public render(){
this._mask.graphics.clear();
this._mask.graphics.beginFill(this.fadeToColor, this._alpha);
this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
this._mask.graphics.endFill();
}
}
}
}

View File

@@ -1,75 +1,77 @@
/**
* SceneTransition用于从一个场景过渡到另一个场景或在一个有效果的场景中过渡
*/
abstract class SceneTransition {
private _hasPreviousSceneRender: boolean;
/** 是否加载新场景的标志 */
public loadsNewScene: boolean;
/**
* 将此用于两个部分的转换。例如淡出会先淡出到黑色然后当isNewSceneLoaded为true它会淡出。
* 对于场景过渡isNewSceneLoaded应该在中点设置为true这就标识一个新的场景被加载了。
module es {
/**
* SceneTransition用于从一个场景过渡到另一个场景或在一个有效果的场景中过渡
*/
public isNewSceneLoaded: boolean;
/** 返回新加载场景的函数 */
protected sceneLoadAction: Function;
/** 在loadNextScene执行时调用。这在进行场景间过渡时很有用,这样你就知道什么时候可以更多地使用相机或者重置任何实体 */
public onScreenObscured: Function;
/** 当转换完成执行时调用,以便可以调用其他工作,比如启动另一个转换。 */
public onTransitionCompleted: Function;
export abstract class SceneTransition {
private _hasPreviousSceneRender: boolean;
/** 是否加载新场景的标志 */
public loadsNewScene: boolean;
/**
* 将此用于两个部分的转换。例如淡出会先淡出到黑色然后当isNewSceneLoaded为true它会淡出。
* 对于场景过渡isNewSceneLoaded应该在中点设置为true这就标识一个新的场景被加载了。
*/
public isNewSceneLoaded: boolean;
/** 返回新加载场景的函数 */
protected sceneLoadAction: Function;
/** 在loadNextScene执行时调用。这在进行场景间过渡时很有用这样你就知道什么时候可以更多地使用相机或者重置任何实体 */
public onScreenObscured: Function;
/** 当转换完成执行时调用,以便可以调用其他工作,比如启动另一个转换。 */
public onTransitionCompleted: Function;
public get hasPreviousSceneRender(){
if (!this._hasPreviousSceneRender){
this._hasPreviousSceneRender = true;
return false;
public get hasPreviousSceneRender(){
if (!this._hasPreviousSceneRender){
this._hasPreviousSceneRender = true;
return false;
}
return true;
}
return true;
}
constructor(sceneLoadAction: Function) {
this.sceneLoadAction = sceneLoadAction;
this.loadsNewScene = sceneLoadAction != null;
}
public preRender() { }
public render() {
}
public async onBeginTransition() {
await this.loadNextScene();
this.transitionComplete();
}
protected transitionComplete() {
SceneManager.sceneTransition = null;
if (this.onTransitionCompleted) {
this.onTransitionCompleted();
constructor(sceneLoadAction: Function) {
this.sceneLoadAction = sceneLoadAction;
this.loadsNewScene = sceneLoadAction != null;
}
}
protected async loadNextScene() {
if (this.onScreenObscured)
this.onScreenObscured();
public preRender() { }
if (!this.loadsNewScene) {
public render() {
}
public async onBeginTransition() {
await this.loadNextScene();
this.transitionComplete();
}
protected transitionComplete() {
SceneManager.sceneTransition = null;
if (this.onTransitionCompleted) {
this.onTransitionCompleted();
}
}
protected async loadNextScene() {
if (this.onScreenObscured)
this.onScreenObscured();
if (!this.loadsNewScene) {
this.isNewSceneLoaded = true;
}
SceneManager.scene = await this.sceneLoadAction();
this.isNewSceneLoaded = true;
}
SceneManager.scene = await this.sceneLoadAction();
this.isNewSceneLoaded = true;
}
public tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection = false): Promise<boolean>{
return new Promise((resolve)=>{
let start = reverseDirection ? 1 : 0;
let end = reverseDirection ? 0 : 1;
public tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection = false): Promise<boolean>{
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();
egret.Tween.get(filter.uniforms).set({_progress: start}).to({_progress: end}, duration * 1000, easeType).call(()=>{
resolve();
});
});
});
}
}
}
}

View File

@@ -1,65 +1,67 @@
class WindTransition extends SceneTransition {
private _mask: egret.Shape;
private _windEffect: egret.CustomFilter;
module es {
export 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 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 async onBeginTransition() {
this.loadNextScene();
await this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType);
this.transitionComplete();
SceneManager.stage.removeChild(this._mask);
}
}
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 async onBeginTransition() {
this.loadNextScene();
await this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType);
this.transitionComplete();
SceneManager.stage.removeChild(this._mask);
}
}
}

View File

@@ -1,34 +1,36 @@
class Viewport {
private _x: number;
private _y: number;
private _width: number;
private _height: number;
private _minDepth: number;
private _maxDepth: number;
public get aspectRatio(){
if ((this._height != 0) && (this._width != 0))
return (this._width / this._height);
return 0;
}
module es {
export class Viewport {
private _x: number;
private _y: number;
private _width: number;
private _height: number;
private _minDepth: number;
private _maxDepth: number;
public get bounds(){
return new Rectangle(this._x, this._y, this._width, this._height);
}
public set bounds(value: Rectangle){
this._x = value.x;
this._y = value.y;
this._width = value.width;
this._height = value.height;
}
public get aspectRatio(){
if ((this._height != 0) && (this._width != 0))
return (this._width / this._height);
return 0;
}
public get bounds(){
return new Rectangle(this._x, this._y, this._width, this._height);
}
public set bounds(value: Rectangle){
this._x = value.x;
this._y = value.y;
this._width = value.width;
this._height = value.height;
}
constructor(x: number, y: number, width: number, height: number){
this._x = x;
this._y = y;
this._width = width;
this._height = height;
this._minDepth = 0;
this._maxDepth = 1;
}
constructor(x: number, y: number, width: number, height: number){
this._x = x;
this._y = y;
this._width = width;
this._height = height;
this._minDepth = 0;
this._maxDepth = 1;
}
}
}